I'd also like to know if there is a way to construct a Map or Set that
differentiates lists and vectors.
To try to answer your question, Juan, I think it's because of the
`clojure.core/=` semantics. From the docstring: "compares numbers and
collections in a type-independent manner." So,
user> (= () [])
true
user> (= (list 1 2 3) (vector 1 2 3))
true
And even nested sequence-like things:
user> (= [1 [2 3]] '(1 (2 3)))
true
In addition, they even hash to the same value:
user> (map hash [ () [] '(1) [1] ])
(1 1 32 32)
It's probably that last property that causes the weird behavior for maps
and sets.
--Leif
On Tuesday, April 3, 2012 12:11:50 AM UTC-7, JuanManuel Gimeno Illa wrote:
>
> Playing with some problems of 4clojure, I wanted to make a map which, for
> each empty collection, returns a keyword. But it seems that it is
> impossible to have both an empty list and an empty vector in the same map.
>
> user=> {() :list}
> {() :list}
> user=> {() :list [] :vector}
> IllegalArgumentException Duplicate key:
> clojure.lang.PersistentList$EmptyList@1
> clojure.lang.PersistentArrayMap.createWithCheck
> (PersistentArrayMap.java:70)
> user=> {[] :vector}
> {[] :vector}
>
> I supposed that this is due to (= [] ()) but
>
> user=> {'(1) :list [1] :vector}
> {(1) :vector}
> user=> (= [1]'(1))
> true
>
> What am I missing?
>
> Juan Manuel
>
--
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