I think I finally see the problem. The "rest expression" in filter's call to lazy-cons has a reference to "coll" in it. That's all it takes for coll to be retained during the entire calculation of the rest.

(defn filter
  "Returns a lazy seq of the items in coll for which
  (pred item) returns true. pred must be free of side-effects."
  [pred coll]
    (when (seq coll)
      (if (pred (first coll))
        (lazy-cons (first coll) (filter pred (rest coll)))
        (recur pred (rest coll)))))

The stye of fix that occurs to me involves peeling off coll from (frest coll) and (rrest coll) before continuing the lazy evaluation.

Posting so someone else can beat me to the answer. :-)

--Steve

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to