This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-12-18
Channels
- # adventofcode (62)
- # aws (5)
- # beginners (59)
- # calva (63)
- # cider (26)
- # cljdoc (1)
- # cljsrn (22)
- # clojure (99)
- # clojure-austin (1)
- # clojure-dev (19)
- # clojure-europe (4)
- # clojure-hamburg (2)
- # clojure-italy (3)
- # clojure-nl (23)
- # clojure-spec (2)
- # clojure-uk (85)
- # clojurescript (41)
- # core-async (17)
- # cursive (20)
- # data-science (11)
- # datascript (2)
- # datomic (31)
- # emacs (7)
- # figwheel (28)
- # figwheel-main (12)
- # graphql (2)
- # hyperfiddle (3)
- # juxt (1)
- # kaocha (2)
- # leiningen (5)
- # nrepl (13)
- # off-topic (45)
- # pathom (13)
- # pedestal (11)
- # re-frame (20)
- # reagent (10)
- # shadow-cljs (92)
- # spacemacs (9)
- # sql (39)
- # tools-deps (32)
- # unrepl (3)
I'm still digging, but fairly confused right now as to some weird behavior I am seeing around ##NaN
I have documented in the recently published Equality guide that not only is (= ##NaN ##NaN)
is false, but that ##NaN
included inside of any collection guarantees that they will not be clojure.core/= to each other, which I think is at least almost always true.
Today I found an exception, which I am sure I must have tried in a REPL before at some time in the past, but at least with Clojure 1.9 and 1.10 it is giving me a surprising result:
user=> (def s1 #{1.0 2.0 ##NaN}) #'user/s1 user=> (def s2 #{##NaN 2.0 1.0}) #'user/s2 user=> (= s1 s2) true
I will let you know if I find out why this is happening, but in case you beat me to the answer...
My best guess right now is that it is due to how the Java equiv
method is implemented on persistent sets, and perhaps the fact that (.equals ##NaN ##NaN)
is true.
Another possibility is that it is related to this behavior:
user=> (identical? ##NaN ##NaN) true user=> (identical? Double/NaN Double/NaN) false
Yeah, this combination of facts is pretty cool:
user=> (identical? ##NaN ##NaN) true user=> (= ##NaN ##NaN) false
"cool" in a mind-blowing, wait-a-second-that-can't-be-right kind of way, I mean.
Seems yes. Or probably not memoized, just a unique object created when Clojure starts up an initializes, probably.
at start up it takes the value of NaN field on the Double class and sticks in it a map (so it gets boxed) and that same boxed value is returned by the reader everytime it reads ##NaN
For the equality guide, I think my plan is simply to soften the language around "always infects collections containing ##NaN" to "usually causes collections containing ##NaN to not be = to each other"
##NaN is an interned symbol so does have identity
right, and that value is cached in the reader