Narvius <narv...@gmail.com> writes:

Hi Narvius,

> So, my question is, why exactly DOESN'T it crash and burn horribly
> with the cries of dying bits in the background? I suppose it has
> something to do with how lazy-seqs work (another mystery for me).

A lazy seq is basically a sequence of the first element and a "thunk",
where a thunk is a function without parameters that knows how to
calculate the rest of the lazy sequence.  When you call `rest' or `next'
on a lazy seq, that thunk is called computing the next item (realizing
it) and the next thunk, which again knows how to compute the rest of the
seq.

So although your lazy-seq function looks recursive, it's actually not.
Any thunk closes over the previous value in the seq, so it can be called
independently.

By the way: that's explained very well (with images and stuff) in The
Joy of Clojure, in case you have that handy.

Bye,
Tassilo

-- 
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

Reply via email to