Tying the knot in Clojure: circular references without (explicit, ugly) mutation?

戏子无情 提交于 2019-12-01 20:18:27

I'm not sure I can answer the question for the general case, but this function seems to solve the particular case.

(defn stream
  [seed]
  (let [step (fn [prev] (for [p prev s seed] (str p s)))]
    (for [x (iterate step seed) y x] y)))

Although I ran into a out of memory exception for a large (dorun (take ...)). So there probably is an issue with this function.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!