Thanks! To confirm my understanding: in my original version I defined (using def) a reference to a lazy sequence. I then evaluated it, using nth to pick a value from the sequence. Because I have a reference to the beginning of the sequence all the lazily generated items are retained. I.e. the lazy sequence is lazy only for the first time it works through the sequence instance, if there is a live reference to the sequence then those now generated elements remain, (to avoid the overhead of regenerating them?).
By providing a function to return a new instance of the sequence each time, as in the solution Meikel has provided, I avoid retaining any references to the front of the sequence, and the garbage collector can do it's work. I always learn much better by making mistakes like these. Cheers, Julian. On Thu, Nov 17, 2011 at 9:49 PM, Meikel Brandmeyer <m...@kotka.de> wrote: > Hi, > > this is a “hold unto head” problem. > > Am 17.11.2011 um 15:06 schrieb Julian Kelsey: > > > (def seq-3s-n-5s > > (filter > > (fn [n] (or (= 0 (mod n 5)) (= 0 (mod n 3)) ) ) > > (iterate inc 1))) > > Here you keep a reference to the head of the generated by iterate. Make it > a function: > > (defn seq-3s-n-5s > [] > (filter #(or (zero? (mod % 5)) (zero? (mod % 3))) (iterate inc 1))) > > Then call it like this: > > (nth (sums (seq-3s-n-5s 0) (Math/pow 10 6)) > > That should fix your problem. > > Sincerely > Meikel > > -- > 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 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