我正在尝试编写一个adjacents
返回序列相邻对向量的函数。所以(adjacents [1 2 3])
会回来[[1 2] [2 3]]
。
(defn adjacents [s]
(loop [[a b :as remaining] s
acc []]
(if (empty? b)
acc
(recur (rest remaining) (conj acc (vector a b))))))
我当前的实现适用于字符串序列,但对于整数或字符,REPL 输出此错误:
IllegalArgumentException Don't know how to create ISeq from: java.lang.Long clojure.lang.RT.seqFrom (RT.java:494)