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

0 votes
in ClojureScript by
In Clojure:


user=> (conj {:a 1} '([:b 2] [:c 3]))
Execution error (ClassCastException) at user/eval3 (REPL:1).
clojure.lang.PersistentVector cannot be cast to java.util.Map$Entry


But in ClojureScript:


cljs.user=> (conj {:a 1} '([:b 2] [:c 3]))
{:a 1, :b 2, :c 3}


There is a check that the entries satisfy {{vector?}}, but we could instead require that they satisfy {{map-entry?}}. In fact, the error message given when {{vector?}} isn't satisfied is: "conj on a map takes _map entries_ or seqables of _map entries_."

Rationale: Even though this change would reject some programs, those programs are incorrect (only accidentally work), and, if ported to Clojure would fail there. Additionally, leveraging the fact that they are map entries would allow access to their keys and values, which can lead to faster code. (See leveraging map entries in CLJS-3116)

4 Answers

0 votes
by

Comment made by: mfikes

CLJS-3115.patch passes CI (/)

0 votes
by

Comment made by: mfikes

CLJS-3115.patch added to Patch Tender (i)

0 votes
by

Comment made by: mfikes

CLJS-3115.patch passes Canary (/)

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