On Wed, Nov 25, 2009 at 09:40:44AM -0800, Gabi 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) . So is
>there some help from the compiler for this? How does the recursive
>call suddenly transfers into a call to a LazySeq object ?
Actually, the compiler doesn't really do anything. lazy-seq is a
macro, a very short one at that. I suggest making sure you have
cloure.contrib.repl-utils available, and just try:
(source lazy-seq)
and see for yourselves. The only real compiler magic is that it sets
the metadata {:once true} on the function it creates which makes for a
bit better code for functions that will only ever be called once.
But yeah,
(defmacro lazy-seq
"..."
[& body]
(list 'new 'clojure.lang.LazySeq (list* '#^{:once true} fn* [] body)))
That's it. The neat thing is that you or I can also write macros that
do this kind of thing. It's one of the things that makes Lisp so
powerful.
David
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en