The REPL automatically realizes the lazy sequence in the process of printing it out, but if you try to us
On Mon, Sep 13, 2010 at 11:07 AM, Ranjit <[email protected]> wrote: > Thanks Armando for catching my stupid mistake. That fixed everything. > > Meikel, I'm not sure I understand what you're saying. When I evaluate > this in the REPL > > (for [x (range 2) y (range 2)] (aset xt x y (+ x y))) > (aget xt 0 0) > (aget xt 1 1) > > I get back 0 and 2 as I expect. Isn't the call to aset consuming the > lazy sequence? > > Thanks. > > On Sep 13, 11:00 am, Meikel Brandmeyer <[email protected]> wrote: >> Hi, >> >> On 13 Sep., 15:07, Ranjit Chacko <[email protected]> wrote: >> >> > (for [x (range 3) y (range 3)] (aset xt x y 1)) >> >> Note that that this will not do what you think it does. for creates a >> lazy sequence which is thrown away immediately. So the aset calls are >> never done. for is a list comprehension, not a looping construct. >> Replace for with doseq. As a rule of thumb: side-effects => command >> starting in "do". >> >> Sincerely >> Meikel > > -- > 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
