This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-20
Channels
- # aws-lambda (7)
- # beginners (113)
- # boot (17)
- # cider (4)
- # cljs-dev (4)
- # clojure (65)
- # clojure-greece (3)
- # clojure-italy (7)
- # clojure-russia (10)
- # clojure-spec (37)
- # clojure-uk (20)
- # clojurescript (76)
- # community-development (2)
- # cursive (24)
- # data-science (9)
- # datomic (9)
- # emacs (1)
- # fulcro (2)
- # graphql (11)
- # hoplon (13)
- # juxt (15)
- # leiningen (1)
- # off-topic (36)
- # om (1)
- # onyx (59)
- # parinfer (41)
- # pedestal (7)
- # portkey (60)
- # protorepl (4)
- # re-frame (345)
- # reagent (7)
- # ring-swagger (16)
- # shadow-cljs (121)
- # spacemacs (30)
- # sql (6)
- # uncomplicate (2)
- # unrepl (9)
- # vim (13)
- # yada (2)
@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
actually, looking at the code in question right now, I can't see a reason to not write a PR using reify
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?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.
@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
@U06BE1L6T Thanks for the example, didn’t know that!
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.
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.
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?
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.
Nothing to do with refs, despite that StackOverflow example.
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.
@rauh Thanks for the explanation. Why is a converted to two different objects? Is it a kind of “lazy” object creation?
@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.
@rauh Yes, that makes sense. And as expected, this also returns true
:
user=> (let [a [Double/NaN]] (= a a))
true
I guess I would have to implement my own =
for collections with numbers to get the above to return false
Somebody use clojure with vert.x?
curious on why would you want that, since clojure has a fair amount of very good tools to handle concurrency on its own
@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)?
I suggest you take a look at https://github.com/Yuppiechef/cqrs-server, might be a good start
hmm, maybe. I've interesting how implement are choreography patter in microservices. Point Lower coupling because of choreography
https://specify.io/concepts/microservices
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
(ImmutableList/of "--log=fatal")
if you have import in ns
Something like
(import '[com.google.common.collect ImmutableList])
(ImmutableList/of "--log=fatal")
thanks @delaguardo and @nha, that was simple. I thought I had to instanciate the class before useing methods.
ah ok, I learned clojure before any object oriented language, so I get confused of basic oo stuff.
I tried that one too, it fails CompilerException java.lang.IllegalArgumentException: No matching ctor found for class com.google.common.collect.ImmutableList
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?
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 ?@fbielejec another "\/\" ?
I'm not sure, but try "/*"
instead of "*"
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.
@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!"))
no luck, well whatever I guess, it's just a dev server, important thing is in production they are resolved
@fbielejec it should work: https://github.com/mhuebert/figwheel-pushstate-server/blob/master/src/figwheel_server/core.clj#L12
@fbielejec actually I use this (c/ANY "/:path{app($|/.*)}" [path] ...)
to match /app
and /app/bla/blubb
but not /apple
check @muebert's repo though for a more complete example - maybe your issue is with something else in the clj file
yeah everyone runs into that
maybe figwheel would accept a patch?
http://2017.clojure-conj.org/datomic-in-cloud/ <-- is this available yet ?
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.
(there's an #off-topic channel for non-Clojure chit-chat BTW) /cc @lewix @taylor
@seancorfield that’s where the conversation continued
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.