预期结果
(reduce-kv vector nil [])
=> nil
(reduce-kv vector nil [1])
=> [nil 0 1]
CLJS 中实际结果
(reduce-kv vector nil (clojure.core.rrb-vector/vec []))
Error: No item 0 in vector of length 0
at Object.cljs$core$vector_index_out_of_bounds [as vector_index_out_of_bounds] (https://127.0.0.1:8080/cljs-runtime/cljs.core.js:19788:8)
at Object.clojure$core$rrb_vector$rrbt$IVecImpl$_array_for$arity$2 (https://127.0.0.1:8080/cljs-runtime/clojure.core.rrb_vector.rrbt.js:1028:18)
at Object.cljs$core$IKVReduce$_kv_reduce$arity$3 (https://127.0.0.1:8080/cljs-runtime/clojure.core.rrb_vector.rrbt.js:613:21)
at Object.cljs$core$_kv_reduce [as _kv_reduce] (https://127.0.0.1:8080/cljs-runtime/cljs.core.js:2359:13)
(reduce-kv vector nil (clojure.core.rrb-vector/vec [1]))
=> [nil 0 1]
CLJ 中实际结果
(reduce-kv vector nil (clojure.core.rrb-vector/vec []))
Execution error (IndexOutOfBoundsException) at clojure.core.rrb_vector.rrbt.Vector/arrayFor (rrbt.clj:806).
(reduce-kv vector nil (clojure.core.rrb-vector/vec [1]))
=> [nil 0 1]
*"vector nil" 这部分在这里不重要,它只是用来证明调用 reduce-kv。
周五晚上,忘记添加任何版本信息
:deps {org.clojure/clojure {:mvn/version "1.10.1"}
org.clojure/clojurescript {:mvn/version "1.10.597"}
org.clojure/core.rrb-vector {:mvn/version "0.1.1"}