Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by

In Clojure, keywords are explicitly cached and interned so that:

(identical? :a :a)

Is true.

In ClojureScript, that's not the case, and the above returns false.

Why is that?

1 Answer

+2 votes
selected by
Best answer

They are in :advanced optimized builds or if you turn on :optimize-contants true in the compiler options.

CLJS adds extra keyword-identical? and symbol-identical? functions which work around the difference.

The reasons it is not done in development builds is mostly because JS didn't have Weak References until very recently and also because of the Closure Compiler not being able to optimize them properly if all keywords are stored in a "global" registry.

So does that means that the data-structure can't rely on identical? for fast equality of keys?
identical? checks reference equality. The reference is the same so it works totally fine.

(def x :a)

(identical? x x) ;; always true