lazy-seq only delays its own evaluation, it is not "recursive" :
(lazy-seq [0 1 2 3]) will evaluate the whole vector as soon as it is
forced. This means that it should wrap the tail of the lazy sequence
you are building.
Consequently, I find that the easiest way to use lazy-seq is as a
second argu
On Apr 30, 2013 5:32 AM, "Liao Pengyu" wrote:
> (def fib
> (lazy-seq
> (concat [0 1] (map + fib (rest fib)
> (take 10 fib) ;; Bomb
The expression (rest fib) forces fib, which is the lazy seq you are already
trying to force when you eval (rest fib).
> (def fib
>
Code:
(def fib
(lazy-seq
(concat [0 1] (map + fib (rest fib)
(take 10 fib) ;; Bomb
Got the error message: _StackOverflowError clojure.lang.RT.more
(RT.java:589)_
And the following solutions works well:
(def fib
(concat [0 1] (lazy-seq (map + fib (rest fib)