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

0 votes
in ClojureScript by

For

`

{1 '1}

`

you get

`

{1 1}

`

9 Answers

0 votes
by

Comment made by: spinningtopsofdoom

This happens for the has-set macro and the hash-set literal. Here's what I get from the repl

`
cljs.user=> (hash-set 1 '1 2 '2 3 '3 4 '4 5)

{1 2 3 4 5}

cljs.user=> (hash-set 1 '1 2 '2 3 '3 4 '4)

{1 1 2 2 3 3 4 4}

cljs.user=> #{ 1 '1 2 '2 3 '3 4 '4}

{2 1 4 4 3 2 1 3}

cljs.user=> #{ 1 '1 2 '2 3 '3 4 '4 5}

{2 1 4 4 3 2 5 1 3}

cljs.user=> #{ 1 '1 2 '2 3 '3 4 '4 5 '5}

{2 5 1 4 4 3 2 5 1 3}

cljs.user=> (apply hash-set [1 '1 2 '2 3 '3 4 '4])

{1 2 3 4}

`

Calling hash-set as a function gives the correct results. The hash-set macro gives the incorrect results until we have more then 8 elements and uses the fromArray method on PersistentHashSet to build the set instead of creating a literal PersistentArrayMap for the set. The literal notation is incorrect no matter how many elements there are.

0 votes
by

Comment made by: rohitaggarwal

The underlying problem for both is the same in that a {{PersistentHashSet}} is being created directly using a {{PersistentArrayMap}} where the keys are the elements from the provided sequence. It manifests itself in two places though.

0 votes
by

Comment made by: rohitaggarwal

I've taken the approach that if we see a quoted constant then don't create the {{PersistentHashSet}} directly and instead go via the {{fromArray}} function.

Patch has the fix and a test.

0 votes
by

Comment made by: mfikes

Attached patch no longer applies to master.

0 votes
by

Comment made by: aralo

It'd be nice if this patch/ticket also included the following case:

(hash-set "a" \a)

0 votes
by

Comment made by: aralo

Should we increase the scope of this ticket? The same issue exists for maps:

{'0 "a", 0 "b"} {\a "a", "a" "b"}

I think one possible solution that solves both, quoting and the char/string, could be to to call {{emit-str}} in {{cljs.compiler}} on the keys/set-members and only then check for uniqueness. Not sure that's a good idea though.

Doesn't solve the {{hash-set}}, {{array-map}} macros.

Edit: Related ticket: CLJS-2087

0 votes
by

Comment made by: dnolen

Increasing the scope of tickets is not desirable. Please move to a separate issue and cross-reference thanks.

0 votes
by

Comment made by: mfikes

Patch no longer applies.

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJS-1587 (reported by mfikes)
...