Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Clojure中映射和集之间的不一致行为_Clojure - Fatal编程技术网

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

Clojure中映射和集之间的不一致行为,clojure,Clojure,史蒂夫·洛什: 这种行为的原因是什么?它被认为是一个缺陷还是存在“形式逻辑”/“集合论”的原因,为什么在持久集合中(整数-1)不等于(长-1)?这是Clojure中的一个缺陷: 满足堆栈溢出愚蠢字符限制的文本位于此处 ; Integers and Longs are equal. (= (Integer. 1) (Long. 1)) true ; Even negative ones. (= (Integer. -1) (Long. -1)) true ; When you use them

史蒂夫·洛什:

这种行为的原因是什么?它被认为是一个缺陷还是存在“形式逻辑”/“集合论”的原因,为什么在持久集合中
(整数-1)
不等于
(长-1)

这是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