On 24/03/2009 1:06, pmf wrote:
> On Mar 24, 12:01 am, Rowdy Rednose<[email protected]> wrote:
>
>> Hi group,
>>
>> say I have 2 sequences
>>
>> (def seq-a '("a1" "a2" "a3"))
>> (def seq-b '("b1" "b2" "b3"))
>>
>> and want to iterate over them in parallel, like this
>>
>> (par-doseq [a seq-a b seq-b] (prn a b))
>>
>> which should print
>>
>> "a1" "b1"
>> "a2" "b2"
>> "a3" "b3"
>>
>
> A combination of the interleave and partition functions would probably
> do what you want:
>
> (partition 2 (interleave [:a :b :c] [:d :e :f]))
>
> (Wrap it in a doall to force your side effects.)
>
>
Another one :
(doseq [[a b] (map vector '(1 2 3) '(a b c))]
(println a b))
(defmacro par-doseq [bindings & body]
(let [bindings (partition 2 bindings)]
`(doseq [~(vec (map first ,bindings)) (map vector ~@(map second
,bindings))]
~...@body)))
cara.nio.echo=> (par-doseq [a '(1 2 3) b '(a b c)] (println a b))
1 a
2 b
3 c
nil
Sacha
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---