Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inconsistent behavior between maps and sets in Clojure

Tags:

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?

like image 964
noahlz Avatar asked Aug 12 '26 23:08

noahlz


1 Answers

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

like image 144
Steve Losh Avatar answered Aug 15 '26 02:08

Steve Losh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!