Hi,

I'm trying to understand the following function (from 
http://en.wikibooks.org/wiki/Clojure_Programming/Examples/Lazy_Fibonacci#Self-Referential_Version):

(def fib-seq
  (lazy-seq
    (map +
      (cons 0 (cons 0 fib-seq))
      (cons 1 fib-seq))))

I'm trying to understand how this works.  In particular, I do not 
understand what the recursive call to fib-seq will return when the sequence 
is lazily evaluated.

Here's my understanding so far:

The first time fib-seq is invoked, it has no head, and the function is the 
tail.  So we go into the first collection, where we append 0 and 0 to 
fib-seq, which then '(0 0) .  This is then mapped with the second 
collection, which (because fib-seq has not returned anything yet) is '(1) . 
 Shouldn't map then raise an error because it is effectively being called 
as (map + (0 0) (1)) ?

I would be very grateful for any insights.

Thanks


-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to