noahlz
noahlz

Reputation: 10311

Inconsistent behavior between maps and sets in Clojure

Steve Losh posted the following Clojure snippet:

; Integers and Longs are equal.
(= (Integer. 1) (Long. 1))
true

; Even negative ones.
(= (Integer. -1) (Long. -1))
true

; When you use them as keys in maps, the maps are still equal.
(= {(Integer. 1) :foo} {(Long. 1) :foo})
true

(= {(Integer. -1) :foo} {(Long. -1) :foo})
true

; When you use positive numbers as keys to sets, they're also equal.
(= #{(Integer. 1)} #{(Long. 1)})
true

; But negative ones aren't. But only in sets. Maps are fine. lol.
(= #{(Integer. -1)} #{(Long. -1)})
false

What is the reason for this behavior? Is it considered a defect or is there a "formal logic" / set theory reason why (Integer. -1) not equaling (Long. -1) in a persistent set?

Upvotes: 3

Views: 121

Answers (1)

Steve Losh
Steve Losh

Reputation: 19852

It's a bug in Clojure: http://dev.clojure.org/jira/browse/CLJ-1106

text to satisfy stack overflow's stupid character limit goes here

Upvotes: 8

Related Questions