clojure - Clojure 中映射和集合之间的行为不一致

标签 clojure

史蒂夫·洛什 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) 在持久集中?

最佳答案

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

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

关于clojure - Clojure 中映射和集合之间的行为不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13312580/

相关文章:

clojure - 如何在 clojure 中创建可执行文件?

Clojure 部分应用程序 - 如何获取 'map' 以返回函数集合?

在 Clojure 中对 Jdbc4Array 进行 Jsonify

python - ConnectionError,最大重试次数超过 url,(由无引起)

java - Systemd: '_JAVA_OPTIONS' 节中的未知左值 'Service'

clojure - 原子和条件 map 更新

clojure - Compojure/Noir 使用 Spring Security 进行身份验证和身份验证?

optimization - Clojure 有短路逻辑吗?

recursion - 迭代过程与递归过程

clojure - 在 deftype 中使用原子时出现奇怪的错误