On 24/03/2009 15:10, Rowdy Rednose wrote:
> Thanks guys, these solutions look much better already.
>
> But do I always have to have these 2 steps
> * merge collection
> * split collection
>
> It feels a bit inefficient, I don't know if it actually is, though.
Allright let's see what we can do :

make a macro out of this :
(loop [a '(1 2 3)
        b '(a b c d)]
   (when (and (seq a) (seq b))
     (println (first a) (first b))
     (recur (rest a) (rest b))))

Might be easier to make a function first
(defn par-doseq-fn [fn & seqs]
   (loop [rests seqs]
     (when (every? identity (map seq rests))
       (apply fn (map first rests))
       (recur (map rest rests)))))

cara=> (par-doseq-fn #(println %1 %2) '(1 2 3) '(a b c))
1 a
2 b
3 c

(defmacro par-doseq [bindings & body]
   (let [bindings (partition 2 bindings)]
     `(par-doseq-fn (fn ~(vec (map first bindings))
              ~...@body)
            ~@(map second bindings))))

cara=> (par-doseq [a '(0 1 2) b '(a b c)] (println a b))
0 a
1 b
2 c
nil

Now you get to run the micro-benchmarks !

Sacha

--~--~---------~--~----~------------~-------~--~----~
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
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