Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
给定一个向量,或者可能是嵌套向量,你如何在 Clojure 中将一个函数在向量(嵌套向量)上迭代 n 次?此外,如何将每一级迭代输出到一个向量中?其中输出向量从初始条件开始,即输入向量(嵌套向量),然后是后续迭代。
我想你想要的是iterate。它返回一个惰性的迭代序列,从输入开始。因此,例如:
iterate
(def init (range 10)) (take 3 (iterate #(map inc %) init)) ;; gives ((0 1 2 3 4 5 6 7 8 9) (1 2 3 4 5 6 7 8 9 10) (2 3 4 5 6 7 8 9 10 11))