Glad I could help. On Tue, Feb 24, 2009 at 1:07 AM, bsmith.occs <bsmith.o...@gmail.com> wrote:
> > > > On Feb 23, 11:46 pm, Jeffrey Straszheim <straszheimjeff...@gmail.com> > wrote: > > Have you figured this out yet? > > > > On Mon, Feb 23, 2009 at 4:58 PM, Jeffrey Straszheim < > > > > straszheimjeff...@gmail.com> wrote: > > > The identifier "fibl" is holding on to the head of the sequence. > > Yes, this works: > > (defn fibl [] > ((fn h [a b] (lazy-seq (cons a (h b (+ a b))))) 0 1)) > > ;; (count (str (last (take 100000 > (fibl))))) > ;; --> 20899 > > by making fibl a function, the head of the sequence is no longer > hanging off some global variable, never to be garbage collected. > > I think I now understand why it's holding on to the head. lazy-seq > evaluates its body only once and then caches the result, which would > be a cons with a number in the car and a lazy-seq in the cdr, which in > turn... tada! full heap! macroexpand-1 gave me the clue I needed: > > => (macroexpand-1 '(lazy-seq (cons a (h b (+ a > b))))) > > (new clojure.lang.LazySeq (fn* [] (cons a (h b (+ a b))))) > > Thanks for the pointer in the right direction! > > // ben > > > --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---