On Mon, Jun 24, 2013 at 8:49 AM, John Gabriele <[email protected]> wrote:
> Why does `into` fail when the 2-element collections are lists and not
> vectors? :
Because the implementation special cases vectors :)
It's the one place where a two element vector is treated like a
Map$Entry so that you are not forced to somehow create Map$Entry
instances for the key/value pairs.
There are some other quirks around that special casing - for example:
user=> (conj {} {:a 1 :b 2})
{:b 2, :a 1}
user=> (conj {} '([:a 1] [:b 2]))
ClassCastException clojure.lang.PersistentVector cannot be cast to
java.util.Map$Entry clojure.lang.APersistentMap.cons
(APersistentMap.java:42)
So conj on a map acts like a map-preserving concat since the second
argument can be a map, not just a new key/value pair to add, yet you
cannot conj a sequence of two-element vectors onto a map.
You can see here that maps contain MapEntry elements, not actual two
element vectors:
user=> (first {:a 1})
[:a 1]
user=> (type (first {:a 1}))
clojure.lang.MapEntry
user=> (type [:a 1])
clojure.lang.PersistentVector
Things can get even stranger if you start doing interop between
Clojure and other languages that have slightly different map
implementations...
--
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/
"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.