Thanks Sean & Carlo for the detailed comments! The gap in my understanding was exactly *how* lazy 'lazy evaluation' is, so the evaluation of 'i' is deferred until it is totally unavoidable.
Just curious, but if I chained a large number of such lazy constructs, isn't there danger of a big unpredictable spike in CPU / Memory if something deeply nested is accessed ? Is there someplace where this is discussed in detail, pros / cons, caveats, concepts etc ? Any books that you think I should read ? Regards Vinay On Tuesday, 31 July 2012 12:05:13 UTC+5:30, Sean Corfield wrote: > > > I tried putting a print and it works as expected. > > Because you are realizing the whole of i to print it. > > > 1) I assumed that printing out [i @a] instead of [@a i] should realize > 'i' > > No, [i @a] creates a two-element vector of a lazy-seq and a value (the > deref of a). Then, when the REPL prints that vector, it realizes the > lazy-seq. > > > 2) If I put a breakpoint in the predicate for take-while, it gets hit ( > I > > Yes, it is hit while i is being realized. > > > 3) This is the strangest observation of all: In the debugger I can see > that > > 'a' is getting incremented, its changing when the breakpoint is hit! > but > > the baffling thing is, when the result is printed out, I still get 0 as > the > > value for a. > > Because the value of @a is bound before i is realized, so 0 is bound > into the vector, and then i is realized during which process you see a > being incremented. > > > Isn't (print i) the same as [i @a] ? since i is realized first, > shouldn't > > @a be correctly printed? > > No, see above. > > > Why is the breakpoint showing me that a is changing ? > > Because it _is_ changing but _after_ the top level of the vector has > been evaluated. > -- > Sean A Corfield -- (904) 302-SEAN > An Architect's View -- http://corfield.org/ > World Singles, LLC. -- http://worldsingles.com/ > > "Perfection is the enemy of the good." > -- Gustave Flaubert, French realist novelist (1821-1880) > -- 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