Here's a bit more of playing around at the repl.

clojure.core=> a b
#<Atom@7b603522: {:color :blu}>
#<Atom@69408a75: {:color :red}>
clojure.core=> (for [[x y] [[a @b] [b @a]]] (swap! x assoc :color (:color y)))
({:color :red} {:color :blu})
clojure.core=> a b
#<Atom@7b603522: {:color :red}>
#<Atom@69408a75: {:color :blu}>
clojure.core=> (for [[x y] [[a @b] [b @a]]] (swap! x merge y))
({:color :blu} {:color :red})
clojure.core=> a b
#<Atom@7b603522: {:color :blu}>
#<Atom@69408a75: {:color :red}>

clojure.core=> (map #(swap! %1 merge %2) [a b] [@b @a])
({:color :red} {:color :blu})
clojure.core=> a b
#<Atom@7b603522: {:color :red}>
#<Atom@69408a75: {:color :blu}>
clojure.core=> (map #(swap! %1 assoc :color (:color %2)) [a b] [@b @a])
({:color :blu} {:color :red})
clojure.core=> a b
#<Atom@7b603522: {:color :blu}>
#<Atom@69408a75: {:color :red}>

note, map & for are lazy, so you'll need a (doall) or something else
to force evaluation (I think).

Or, you could just use doseq

clojure.core=> a b
#<Atom@7b603522: {:color :blu}>
#<Atom@69408a75: {:color :red}>
clojure.core=> (doseq [[x y] [[a @b] [b @a]]] (swap! x assoc :color (:color y)))
nil
clojure.core=> a b
#<Atom@7b603522: {:color :red}>
#<Atom@69408a75: {:color :blu}>
clojure.core=> (doseq [[x y] [[a @b] [b @a]]] (swap! x merge y))
nil
clojure.core=> a b
#<Atom@7b603522: {:color :blu}>
#<Atom@69408a75: {:color :red}>

Cheers, Jay

On Mon, Jan 30, 2012 at 8:07 AM, Meikel Brandmeyer (kotarak)
<m...@kotka.de> wrote:
> Hi again,
>
> or more like this:
>
> (defn exchange!
>   [a b & {:keys [f] {f (fn [_ v] v)}}]
>
>   (let [av @a bv @b]
>     (alter a f bv)
>     (alter b f av)))
>
> (defn exchange-color!
>   [a b]
>   (exchange! a b :f #(assoc %1 :color (:color %2))))
>
> (exchange-color! a b)
>
>
> Sincerely
> Meikel
>
> --
> 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

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