2012/9/5 Andy Fingerhut <andy.finger...@gmail.com> > If someone types in the literal map {:a 5 :b 10 :c 13 :a -5}, what is the > "correct thing"? > > Some people might be thinking the correct thing is "I want the last key > :a's value, -5, to win always, no matter if the key :a occurs more than > once. I never want an error for code like this." > > Others might be thinking "Oh, that is obviously a typo in my source code. > I never intentionally want to specify the same key twice in any literal > map. I want the compiler to flag that as an error so I don't have to spend > lots of testing/debugging time to find that typo." >
Why not _only_ throw, if the keys are provably identical? The _reader_ can decide this on a purely syntactic basis. So {:a 1 :a 2}, would throw. (let [a :a] {a 1 a 2}) would also throw. (let [a1 :a a2 :a] {a1 1 a2 2}) would eliminate the duplicate key with last one in wins behavior, as it was before. Maybe it could print a warning, doing so. As it happens, this catches all the obvious cases, like config-maps (where it has already saved me once), while leaving more involved semantics alone. Can I cast a vote that this is the most desirable behavior? I'll start with +1 for throwing on _syntactic_ duplicates -- 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