Re: Problems with map of empty collections
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 clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Problems with map of empty collections
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 clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Problems with map of empty collections
Another interesting fact is that: Clojure 1.2.1 user= {'(1) :list [1] :vector} java.lang.IllegalArgumentException: Duplicate key: (1) (NO_SOURCE_FILE:0) Clojure 1.3.0 user= {'(1) :list [1] :vector} {(1) :vector} Clojure 1.4.0-beta1 user= {'(1) :list [1] :vector} {(1) :vector} ...but I don't know what's going on. On Tuesday, April 3, 2012 9:11:50 AM UTC+2, 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 clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Problems with map of empty collections
More examples in clojure 1.3.0: user= {[1 2 3] :vector '(1 2 3) :list} {[1 2 3] :list} but user= #{[1 2 3] (1 2 3)} IllegalArgumentException Duplicate key: (1 2 3) clojure.lang.PersistentHashSet.createWithCheck (PersistentHashSet.java:68) ... anyone has an explanation? Juan Manuel On Tuesday, April 3, 2012 10:55:26 AM UTC+2, mnicky wrote: Another interesting fact is that: Clojure 1.2.1 user= {'(1) :list [1] :vector} java.lang.IllegalArgumentException: Duplicate key: (1) (NO_SOURCE_FILE:0) Clojure 1.3.0 user= {'(1) :list [1] :vector} {(1) :vector} Clojure 1.4.0-beta1 user= {'(1) :list [1] :vector} {(1) :vector} ...but I don't know what's going on. On Tuesday, April 3, 2012 9:11:50 AM UTC+2, 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 clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Problems with map of empty collections
I think quoting plays a part here: Clojure 1.3.0 user= {(list 1 2 3) :list [1 2 3] :vec} IllegalArgumentException Duplicate key: (1 2 3) clojure.lang.PersistentArrayMap.createWithCheck (PersistentArrayMap.java:70) Stuart On 3 April 2012 22:41, JuanManuel Gimeno Illa jmgim...@gmail.com wrote: More examples in clojure 1.3.0: user= {[1 2 3] :vector '(1 2 3) :list} {[1 2 3] :list} but user= #{[1 2 3] (1 2 3)} IllegalArgumentException Duplicate key: (1 2 3) clojure.lang.PersistentHashSet.createWithCheck (PersistentHashSet.java:68) ... anyone has an explanation? Juan Manuel On Tuesday, April 3, 2012 10:55:26 AM UTC+2, mnicky wrote: Another interesting fact is that: Clojure 1.2.1 user= {'(1) :list [1] :vector} java.lang.**IllegalArgumentException: Duplicate key: (1) (NO_SOURCE_FILE:0) Clojure 1.3.0 user= {'(1) :list [1] :vector} {(1) :vector} Clojure 1.4.0-beta1 user= {'(1) :list [1] :vector} {(1) :vector} ...but I don't know what's going on. On Tuesday, April 3, 2012 9:11:50 AM UTC+2, 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 clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com 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 post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en