Possible Duplicate:
Recursive function causing a stack overflow
Working through the example lazy-seq here.
(defn sieve [s]
(cons (first s)
(lazy-seq (sieve (filter #(not= 0 (mod % (first s)))
(rest s))))))
If I try to generate more than a couple of thousand primes or so, I get an OutOfMemoryError. Based on my research (but I am very new to clojure) I suspect this may be a problem of the class "hold onto head" but cannot figure out why that would be or how it might be remedied. How can this function be altered so as not to run out of memory when generating larger numbers of primes?