Fork me on GitHub
#clojure
<
2017-10-20
>
bja04:10:44

@alexmiller I've seen that elsewhere (on HN or Reddit, perhaps from you?) and it only bit me because I didn't realize that metrics-clojure macros (codahale metrics wrapper) has a time! that proxies java.util.concurrent.Callable

bja04:10:05

actually, looking at the code in question right now, I can't see a reason to not write a PR using reify

hiredman04:10:03

fns are Callable

hiredman04:10:31

(no need to reify or proxy anything)

grav05:10:35

user=> (= Double/NaN Double/NaN)
false
user=> (def a Double/NaN)
#'user/a
user=> (def b a)
#'user/b
user=> (= a b)
true
Is this the correct behaviour, ie that = compares identity instead of value?

Alex Miller (Clojure team)11:10:41

That's not the right inference. = compares values but checks for identity as a shortcut special case. This is the rare case where you're seeing an object that is identical but not equals. (I think function instances also fall into this category). In some sense I'd say these examples show that the assumption of identical means equal is wrong.

rauh06:10:49

@grav Always use == for number comparison.

jumar07:10:58

@rauh @grav don't use == unless you understand the consequences. Most of the time, = is the right thing to use:

user=> (= 17 17.0)
false
user=> (== 17 17.0)
true
user=> (== 17 17.0000000000000001)
true

rauh07:10:44

Good point!

grav07:10:31

@U06BE1L6T Thanks for the example, didn’t know that!

rauh06:10:10

1. Why this is happening: = first checks for identical? and gives true if it's the same object. 2. The top level def converts the Primitive Double/NaN to an object. You could avoid that by using ^:const on the var.

rauh06:10:43

Fun fact:

rauh06:10:39

Here it's false, since the local binding a is a primitive and Clojure will properly call clojure.lang.Util.equiv(double, double) which returns false for the primitives. As expected.

xtreak2906:10:17

Sorry if it has been a repetitive question what are the benefits of namespaced keys ? I get that one namespace might modify other namespace keys so is it only useful for cases where we use refs as in https://stackoverflow.com/a/2482098/2610955 ? Is it used just to have different keys separated by namespace to avoid collision?

seancorfield16:10:09

Namespace-qualifiers let you ensure that keywords are globally unique. Suppose you have an person name and a car name in different parts of your application -- rather than calling them both :name, you would call them :person/name and :car/name so that you can tell what type of name you have in any given map. clojure.spec has made namespace-qualified keywords more visible but they've always been good practice. Spec also lets you handle unqualified keys in maps while using qualified names in order to keep the specs separate.

seancorfield16:10:37

Nothing to do with refs, despite that StackOverflow example.

xtreak2906:10:48

I also see it is recommended a lot in spec. The docs say > The use of namespaces ensures that we can define reusable non-conflicting specs across libraries or applications. Any example of the same will be helpful and why we need to have same key names separated by namespace since by definition a map must have unique keys.

grav07:10:50

@rauh Thanks for the explanation. Why is a converted to two different objects? Is it a kind of “lazy” object creation?

rauh07:10:22

@grav Sorry that was wrong what I said, I'll edit it. Correct is: (let [a Double/NaN) (identical? a a)) is false since identical is only defined for Object so they get boxed by clojure.lang.Number.num() to two different objects and returns false. However for (let [a Double/NaN] (= a a)) it's false since the inline version = is clojure.lang.Util/equiv which is defined for the signature double, double and returns false since the two primitves are not equal.

rauh07:10:24

The thing with using def is that it'll always be an Object unless you ^:const it.

grav07:10:30

@rauh Yes, that makes sense. And as expected, this also returns true:

user=> (let [a [Double/NaN]] (= a a))
true

grav07:10:32

I guess I would have to implement my own = for collections with numbers to get the above to return false

rauh07:10:29

@grav Yeah, i'm pretty sure all the equal fns/methods will first check for identical

fantomofdoom08:10:25

Somebody use clojure with vert.x?

sfalcon08:10:20

curious on why would you want that, since clojure has a fair amount of very good tools to handle concurrency on its own

fantomofdoom08:10:45

@sfalcon not for concurrency, but for use event bus.I can't find event bus, or somthing like this in clojure. Are you develop react architecture (microservices + event etc)?

sfalcon08:10:35

I suggest you take a look at https://github.com/Yuppiechef/cqrs-server, might be a good start

fantomofdoom08:10:27

hmm, maybe. I've interesting how implement are choreography patter in microservices. Point Lower coupling because of choreography https://specify.io/concepts/microservices

hlolli11:10:36

how do I write this java statement in clojure

ImmutableList.of("--log=fatal")
where the class ImmutableList is imported from com.google.common.collect.ImmutableList

delaguardo11:10:12

(ImmutableList/of "--log=fatal") if you have import in ns

nha11:10:08

Something like

(import '[com.google.common.collect ImmutableList])
(ImmutableList/of "--log=fatal")

hlolli11:10:00

thanks @delaguardo and @nha, that was simple. I thought I had to instanciate the class before useing methods.

nha11:10:16

this is a static method so you don’t have to

hlolli11:10:03

ah ok, I learned clojure before any object oriented language, so I get confused of basic oo stuff.

nha11:10:12

Otherwise it would have looked like

(.of (ImmutableList.) "--log=fatal")

hlolli11:10:49

I tried that one too, it fails CompilerException java.lang.IllegalArgumentException: No matching ctor found for class com.google.common.collect.ImmutableList

hlolli11:10:24

ah otherwise as in non-static method, sorry

tomaas12:10:30

hi, im using [com.google.firebase/firebase-admin "5.3.1"] and doing uberjar I get an error. When using gradle in java project that same error can be fixed adding apply plugin: 'com.google.gms.google-services' . Can I do something similar in project.clj?

fbielejec12:10:13

I'm trying to define a handler that for all methods and paths responds with http-ok:

(def web-handler 
  (-> (compojure/routes
       (ANY "*" _ {:status 200})
       (route/not-found "Page not found"))))
but the path matching seems to work only for http://domain/foo and not http://domain/foo/bar ?

hlolli12:10:44

@fbielejec another "\/\" ?

metametadata12:10:47

I'm not sure, but try "/*" instead of "*"

fbielejec13:10:11

I think "/*" is equivalent to what I have - the problem is it's a ring handler for a figwheel build, and trying = restarting build. Not the REPL but still slow.

hlolli13:10:28

@fbielejec this is how my figwheel handler looks like, always fetches index.html

(defroutes main-routes
  (route/files "/" {:root "public"})
  (route/resources "/")
  (GET "*" []  (resource-response "index.html" {:root "public"}))
  (route/not-found "404 Page not found!"))

fbielejec13:10:12

no luck, well whatever I guess, it's just a dev server, important thing is in production they are resolved

pesterhazy13:10:02

@fbielejec actually I use this (c/ANY "/:path{app($|/.*)}" [path] ...) to match /app and /app/bla/blubb but not /apple

pesterhazy13:10:24

check @muebert's repo though for a more complete example - maybe your issue is with something else in the clj file

fbielejec13:10:08

this could work, it's exactly for this use case, pushstate URLs 🙂

pesterhazy13:10:56

yeah everyone runs into that

pesterhazy13:10:20

maybe figwheel would accept a patch?

qqq13:10:00

I don't see that on the webpage -- is this from the talk ?

seancorfield16:10:09

Namespace-qualifiers let you ensure that keywords are globally unique. Suppose you have an person name and a car name in different parts of your application -- rather than calling them both :name, you would call them :person/name and :car/name so that you can tell what type of name you have in any given map. clojure.spec has made namespace-qualified keywords more visible but they've always been good practice. Spec also lets you handle unqualified keys in maps while using qualified names in order to keep the specs separate.

lewix19:10:26

hows everything

taylor20:10:18

weather’s nice

lewix20:10:13

@taylor where you located

seancorfield20:10:32

(there's an #off-topic channel for non-Clojure chit-chat BTW) /cc @lewix @taylor

lewix20:10:23

@seancorfield that’s where the conversation continued

boldaslove15623:10:08

Question here, not like HTTP REST where you return a specific HTTP status for a specific condition, there's no definite rule for error handling in Websocket right? I could just return a map like {:error :conflict} to indicate there's a db conflict.