Duplicate keys in maps/sets are disallowed in literals and factory functions,
where data is generally literal & inline and therefore likely represents coder
error:
; all disallowed
#{:a :a}
{:a 1 :a 2}
(hash-map :a 1 :a 2)
(hash-set :a :a)
They are allowed in other contexts, where the data could come from anywhere:
; dumb, but these forms not generally called with a literal
(set [:a :a])
(into #{} [:a :a])
I find this behavior consistent and easy to explain, but I was involved in the
design conversation so maybe I have participant blindness. :-)
Stu
> On Fri, 25 Jun 2010 15:36:31 +0200
> Michael Wood <[email protected]> wrote:
>
>> On 25 June 2010 12:27, Tim Robinson <[email protected]> wrote:
>>> I tried Clojure via Githhub today.
>>>
>>> Anyone notice this bug that hadn't existed in Version 1.1
>>>
>>> user=> #{:item1 {:a "A" :b "B"} :item2 {:a "A" :b "B"}}
>>> java.lang.IllegalArgumentException: Duplicate key: {:a "A", :b "B"}
>>
>> You're trying to put duplicate values into a set.
>
> So? Most places, putting a value that's already in a set into the set
> is a nop. Even in clojure that exhibits the above behavior:
>
> user=> #{:a :a}
> java.lang.IllegalArgumentException: Duplicate key: :a
> user=> (set [:a :a])
> #{:a}
> user=> (conj #{:a} :a)
> #{:a}
> user=>
>
> Apparently, duplicate keys in sets are only disallowed in set
> literals. Arguably, that must be a mistake on the users part, but
> it sure seems to clash with the behavior of sets elsewhere.
>
> <mike
> --
> Mike Meyer <[email protected]> http://www.mired.org/consulting.html
> Independent Network/Unix/Perforce consultant, email for more information.
>
> O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
>
> --
> 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 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