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 argument to cons: (def fib (cons 0 (cons 1 (lazy-seq (map + fib (rest fib)))))) but that might come from my playing with The Little Schemer. On 1 May 2013 19:51, Stephen Compall <stephen.comp...@gmail.com> wrote: > On Apr 30, 2013 5:32 AM, "Liao Pengyu" <arise...@gmail.com> 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 >> (concat [0 1] (lazy-seq (map + fib (rest fib))))) ;; Works well > > Whereas here, fib has already been forced when you call (rest fib), > >> (def fib >> (lazy-cat [0 1] (map + fib (rest fib)))) ;; Works well > > And here forcing fib doesn't eval (rest fib). > >> All of the above program using lazy-seq > > As you have seen, lazy-seq is not a silver bullet. > > -- > Stephen Compall > If anyone in the MSA is online, you should watch this flythrough. > > -- > -- > 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/groups/opt_out. > > -- -- 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/groups/opt_out.