This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # adventofcode (78)
- # announcements (12)
- # babashka (2)
- # beginners (116)
- # calva (20)
- # cider (17)
- # clj-kondo (15)
- # cljs-dev (51)
- # clojure (32)
- # clojure-android (1)
- # clojure-dev (4)
- # clojure-europe (91)
- # clojure-gamedev (1)
- # clojure-italy (2)
- # clojure-nl (1)
- # clojure-spec (12)
- # clojure-taiwan (1)
- # clojure-uk (10)
- # clojurescript (9)
- # conjure (3)
- # cryogen (4)
- # cursive (4)
- # data-science (1)
- # datomic (5)
- # depstar (5)
- # fulcro (39)
- # google-cloud (2)
- # kaocha (2)
- # malli (7)
- # off-topic (3)
- # pathom (3)
- # pedestal (5)
- # re-frame (19)
- # rewrite-clj (54)
- # ring (3)
- # shadow-cljs (12)
- # spacemacs (12)
- # specter (3)
- # tools-deps (63)
Hello folks! Just to confirm, there are something special that breaks clojurescript hash-map when keys are
Seems like they are broken:
> (def s1 (js/Symbol "1")) #'cljs.user/s1 > (contains? (array-map s1 :a) s1) true > (contains? (hash-map s1 :a) s1) false
@niwinz symbols don't have good equality semantics in JS, but I suppose if this works for
Object it should work for
symbols in js are unique, this is why we are using them, is the fastest way to generate a value that is different of other values
note if you don't hold onto this somehow you'll never be able to retrieve the value again
probably this is an easy one? I think we don't have a hashing case for symbols or something like that
hmm i think i don't have access to jira, should I need to write this on http://ask.clojure.org?
i confirm, i don't have access to jira for open the issue; that is ok, just tell me where i can open the issue
yeah Symbols aren't currently hashable (we cannot add hash property w/ goog.getUid for random objects). So thinking we should probably get the string value of the Symbol and hash that?
wouldn't that break their equality semantics? if
Symbol("a") the hash can't be based on the string value?
What about putting the guid in a WeakMap keyed by symbol? nm, looks like symbols are not allowed as weakmap keys
arguments here: https://github.com/tc39/ecma262/issues/1194
symbols are allowed as keys in Maps though, so symbols could still have a guid hash value in there instead of a WeakMap. The downside is that symbols not created from the global registry (i.e. Symbols made by Symbol(…) not Symbol.for(…)) will never be GC’d. Symbols made by Symbol.for(…) are already not GCed so no loss there.
did i read correctly that while they can be keys in maps they "are not enumerable in for...in iterations."
Maps don’t have a useful for-in. The point of them is to be able to safely store any key without worrying about colliding with the properties of the js object that implements Map itself. you can use for-of though
It is acceptable correctness-wise for things that are not equal to have the same hash value -- just leads to poor hashing performance if you have too many such objects with the same hash value in the same hashable collection simultaneously.
You would get terrible hashing performance if the hash of every object/value was 0, but it would not break equality semantics.
I am relying on symbols not being
identical? to each other even when created with the same string in CLJS code:
(identical? (symbol "a") (symbol "a")) ;;=> false