This is due to the fact that the evaluation of a do form returns the last expr...
Le mercredi 6 juin 2012 12:23:07 UTC+2, Jim foo.bar a écrit : > > It's obvious that you're looking for: > > (def lazy1 (interleave (repeat '+) (range 3))) > > > but I still haven't figured out why you get: (+0 +1 2) when using > iterate! > > Jim > > > > On 06/06/12 11:13, Jim - FooBar(); wrote: > > From the docs: > > > > clojure.core/iterate > > ([f x]) > > Returns a lazy sequence of x, (f x), (f (f x)) etc. f must be free > > of side-effects > > > > Your f is NOT free of side-effects...Nonetheless, I would expect (0 > > +1 +2) instead of (+0 +1 2)! > > Can anyone shine some light on this? > > > > Jim > > > > On 06/06/12 10:24, Z.A wrote: > >> Hi > >> > >> user=> (def lazy1 (take 3 (iterate #(do (print > >> "+") (inc %)) 0))) > >> #'user/lazy1 > >> user=> lazy1 > >> (+0 +1 2) > >> > >> Why am I not getting (+0 +1 +2) ? > >> > >> Thanks > >> Zubair > >> > >> PS: I am reading chapter 6 of 'The Joy of Clojure' and trying to > >> understand "rest versus next" , pp 116 > >> > >> -- > >> You received this message because you are subscribed to the Google > >> Groups "Clojure" group. > >> To post to this group, send email to [email protected] > >> Note that posts from new members are moderated - please be patient > >> with your first post. > >> To unsubscribe from this group, send email to > >> [email protected] > >> 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 post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en
