게으름을 이해하는 데 어려움을 겪고 있습니다.Clojure에서 가장 단순한 게으름 함수
사람은 아래에있는 내 기능
(defn my-red
([f coll] (my-red f (first coll) (rest coll)))
([f init coll]
(let [mr (fn [g i c d]
(if (empty? c) d
(recur g (g i (first c)) (rest c) (conj d (g i (first c))))))]
(lazy-seq (mr f init coll [])))))
게으른없는 이유 clojure.org/lazy에 대해,이 예제는 filter
의 게으름가 호출에서 오는
(defn filter
"Returns a lazy sequence of the items in coll for which
(pred item) returns true. pred must be free of side-effects."
[pred coll]
(let [step (fn [p c]
(when-let [s (seq c)]
(if (p (first s))
(cons (first s) (filter p (rest s)))
(recur p (rest s)))))]
(lazy-seq (step pred coll))))