我想要生成一个相对较小的(1296元素)列表的基本上枚举4个基地6位数从[0 0 0 0]到[5 5 5 5]为什么我得到一个函数StackoverflowError没有明确的递归
[0 0 0 0], [1 0 0 0] ... [5 0 0 0], [0 1 0 0] ... [5 5 5 5]
目前我有什么是:
(letfn [(next-v [v]
(let [active-index (some (fn [[i e]] (when (> 5 e) i))
(map-indexed vector v))]
(map-indexed #(cond
(> active-index %1) 0
(= active-index %1) (inc %2)
:else %2)
v)))]
(last (take 1290 (iterate next-v [0 0 0 0]))))
这工作,但它最终吹堆栈。
我在这里做什么导致StackOverflowError? 我怎样才能构建我的代码,使其“安全”? 有没有更好的方式来做我想做的事情?
其他两个类似的问题:http://stackoverflow.com/questions/2946764/recursive-function-causing-a-stack-overflow http://stackoverflow.com/questions/24958907/why-does-reduce-give -a-stackoverflowerror-in-clojure –