Looping variables in a clojure "for" loop are iterated in a serial,
cartesian fashion:

> (for [a (range 5) b (range 10 15)]
       (+ a b))
(10 11 12 13 14 11 12 13 14 15 12 13 14 15 16 13 14 15 16 17 14 15 16
17 18)

I was wondering if there's a standard idiom for looping in parallel
fashion- Doesn't look like it's supported by the "for" macro directly.
The best code I can come up with to do this is:

> (for [[a b] (map vector (range 5) (range 10 15))]
       (+ a b))
(10 12 14 16 18)

Is there a more elegant way to do this? (Of course, having parallel
for loop variables is only valuable if you have a more complex loop-
For this simple example you could write this in a nicer way by not
using a "for" loop at all)

On a side note, is there a good reason why "range" with no parameters
doesn't just return the whole numbers? Then I wouldn't have to pepper
my code with (iterate inc 0) everywhere...
-- 
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

Reply via email to