2017-08-11 94 views
0

起初我以为这是一个错误,但看看源代码显然是故意的。有人知道为什么这样做吗?它与Clojure不兼容,也是错误的微妙来源。ClojureScript漂浮散列作为整数

(hash 1) ; => 1 
(hash 1.5) ; => 1 

https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/core.cljs#L985

(defn hash 
    "Returns the hash code of its argument. Note this is the hash code 
    consistent with =." 
    [o] 
    (cond 
    (implements? IHash o) 
    (bit-xor (-hash ^not-native o) 0) 

    (number? o) 
    (if (js/isFinite o) 
     (js-mod (Math/floor o) 2147483647) 
     (case o 
     Infinity 
     2146435072 
     -Infinity 
     -1048576 
     2146959360)) 
    ...)) 

回答