On Mon, Nov 9, 2009 at 12:52 PM, Andrew Boekhoff <boekho...@gmail.com>wrote:
> Hi. > > And gives very different results. 'for' iterates over it's sequences > > in a nested fasion. For your particular example, it will return the > > sequence from (+ 31 1) (+ 31 2) and so on, and never get to the second > > element of the first vector. > > I like it. I was recently wondering about a convenient expression > for this type of iteration. I wonder if it could be supported > with a new keyword in for? > > maybe: > (for [ x [42 17 25] > :with [ y (iterate inc 1)]] > (+ x y)) > > Unfortunately I have no suggestions for an implementation, but it would > complement all the syntactical niceties already offered by for. I was thinking this myself; or at least a tandem-for that iterates its collections in tandem like map instead nested. As far as implementation goes, right now if I wanted to do something like that using for I'd write (for [[x y] (map vector [42 17 25] (iterate inc 1))] (+ x y)) There's also (partition 2 (interleave ...)) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---