I've been playing with lazy sequences defined by autoreferential
definition. For instance:

(def ones (lazy-seq (cons 1 ones)))

which is equivalent to (def ones (repeat 1)).

My problem arises when defining the sequence of fibonacci numbers.
With this definition:

(def fibs
  (lazy-seq (list* 0 1 (map + fibs (drop 1 fibs)))))

all works, for instance:

user=> (take 10 fibs)
(0 1 1 2 3 5 8 13 21 34)

But if I change (drop 1 fibs) with (rest fibs), that is:

(def fibs
  (lazy-seq (list* 0 1 (map + fibs (rest fibs)))))

and try to get the first 10, I get:

user=> (take 10 fibs)
java.lang.StackOverflowError

My problem is that I don't understand why.

Thanks in advance,

Juan Manuel

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