On Sat, Mar 20, 2010 at 8:05 AM, WoodHacker <ramsa...@comcast.net> wrote:
> When I run the following: > > (for [y (range 4)] (for [x (range 4)] (println x y))) > > I get what I expect - 0 0, 1 0, 2 0, 3 0 etc., but at the end of > each y loop I also get 4 nils. > > ((0 0 > 1 0 > 2 0 > 3 0 > nil nil nil nil) (0 1 > 1 1 > 2 1 > 3 1 > nil nil nil nil) (0 2 > > What's going on? And how do I fix it? Adding a :when to test for > nil does not seem to do anything. > > Bill > for is not a for loop as pointed out by Michael, it's a list comprehension (similar to Python and Haskell). It produces a lazy sequence. You can do what you want with the following: (doseq [[x y] (for [y (range 4) x (range 4)] [x y])] (println x y)) -- 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 To unsubscribe from this group, send email to clojure+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.