Clojure中地图和集合之间的行为不一致

时间:2012-11-09 17:01:38

标签: 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

这种行为的原因是什么?它被认为是缺陷还是存在“形式逻辑”/集理论的原因,为什么(Integer. -1)在持久集中不等于(Long. -1)

1 个答案:

答案 0 :(得分:7)

这是Clojure中的一个错误:http://dev.clojure.org/jira/browse/CLJ-1106

文本以满足堆栈溢出的愚蠢字符限制在这里