On Wed, Nov 25, 2009 at 12:40 PM, Gabi <bugspy...@gmail.com> wrote: > Very interesting indeed. I am not sure I understand completely, but by > intuition I presume that the recursive call actually creates a new > heap allocated LazySeq (with the function definition inside) .
Not quite; it creates a Java object one method of which calls your function to generate a) the next element and b) another such Java object, which in turn would be used to generate the *next* element, and so on. When you walk the sequence, you get a series of sequential method calls to these objects in the JVM, one after the next (not nested), so no stack overflow. Well, except that when you repeatedly transform lazy sequences or wrap lazy sequences in lazy sequences (most usually a problem with (reduce (mapcat ...)) and (reduce (filter ...)))), the nesting depth of calls can get high enough to be a problem as each lazy sequence call wraps a call to some transformed sequence, which wraps another, which wraps another... -- 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