3

Steve Losh发布 了以下 Clojure 片段

; 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)持久集合?

4

1 回答 1

8

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

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

于 2012-11-09T17:06:18.300 回答