Conrad,
What's your use case that requires for and not map?  I haven't seen
something like this yet, and you've got my curious.

Sean

On Jan 8, 4:41 pm, Conrad <drc...@gmail.com> wrote:
> Thanks again Sean/Chouser- Sounds like there isn't any easy way to do
> in-step iteration using the "for" construct, as I suspected- This is
> of course easily remedied for writing a convenience function for "(map
> vec ...)"
>
> (As I mentioned in the top post, I am aware the simple example I gave
> can be written more elegantly without the "for" construct.)
>
> On Jan 8, 2:07 pm, Sean Devlin <francoisdev...@gmail.com> wrote:
>
>
>
> > Oh, right.  I saw "paralell" and the brain hit autopilot.
>
> > And I think you CAN improve on your fn a little bit.  This should do
> > the trick
>
> > (map + (range 1 5) (range 11 15))
>
> > The mapping fn itself will be applied to as many arguments as you have
> > collections.  Since + is variadic, it will do the job nicely.
>
> > Sean
>
> > On Jan 8, 11:56 am, Chouser <chou...@gmail.com> wrote:
>
> > > On Fri, Jan 8, 2010 at 11:34 AM, Sean Devlin <francoisdev...@gmail.com> 
> > > wrote:
> > > > Take a look at pmap
>
> > > I don't think that's the kind of "parallel" being asked about.
>
> > > > On Jan 8, 11:13 am, Conrad <drc...@gmail.com> wrote:
> > > >> 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?
>
> > > Probably not. 'map' is the primary way to walk multiple seqs in
> > > step.  'zipmap' does this too, though only for building
> > > a hash-map.  Of course you can always use recur as well.
>
> > > --Chouser
> > > --
> > > -- I funded Clojure 2010, did you?
-- 
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