All - I'm trying to generate a lazy sequence of primes using Erastosthenes Sieve (from Abelson & Sussman) and am encountering some issues with lazy sequence.
Here's what I have: --- (defn divisible? [input numerator] (= 0 (mod input numerator))) (defn sieve [stream] (lazy-seq (cons (first stream) (sieve (filter #(not (divisible? % (first stream))) (rest stream)))))) (def primes (sieve (iterate inc 2))) --- This is fine now when I: => (take 5 (drop 1000 primes)) (7927 7933 7937 7949 7951) But when I: => (take 5 (drop 4000 primes)) StackOverflowError clojure.lang.LazySeq.sval (LazySeq.java:40) -- I understand how the StackOverflow occurs with the filter on the recursively generated sequence... however I can't think of a way to make this work.. I'm pretty new to clojure so I'm not very familiar with all of the language features; is there some tool to help me realize this or should I just go about the implementation in a different way? Thanks - have a great morning! Matty -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.