lazy-seq and stack overflow for infinite sequences
问题 I am trying to show the importance of lazy-sequences or lazy-evaluation to the non-FP programmers. I have written this implementation of prime-generation to show the concept: (defn primes-gen [sieve] (if-not (empty? sieve) (let [prime (first sieve)] (cons prime (lazy-seq (primes-gen (filter (fn [x] (not= 0 (mod x prime))) (rest sieve)))))))) ;;;;; --------- TO SHOW ABOUT THE LAZY-THINGS ;; (take 400 (primes-gen (iterate inc 2))) ;; (take 400 (primes-gen (range 2 1000000000000N))) However, i