Re: For loop question

2010-03-21 Thread Michał Marczyk
On 20 March 2010 17:17, David Nolen wrote: > You can do what you want with the following: > > (doseq [[x y] (for [y (range 4) x (range 4)] [x y])] >   (println x y)) Or just (doseq [y (range 4) x (range 4)] (println x y)) doseq really has exactly the same syntax as for (including supp

Re: For loop question

2010-03-20 Thread David Nolen
On Sat, Mar 20, 2010 at 8:05 AM, WoodHacker 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 >

Re: For loop question

2010-03-20 Thread DmitriKo
I guess you want this: (for [x (range 4) y (range 4)] (str x y)) -- DmitriKo On Mar 20, 2:05 pm, WoodHacker 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 als

Re: For loop question

2010-03-20 Thread Michał Marczyk
On 20 March 2010 13:05, WoodHacker wrote: > What's going on?   And how do I fix it?    Adding a :when to test for > nil does not seem to do anything. You'll want to use 'doseq' in place of 'for'. It uses exactly the same syntax as for, but is used solely for side effects (the return value is nil)

Re: For loop question

2010-03-20 Thread Heinz N. Gies
On Mar 20, 2010, at 13:05 , WoodHacker 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