Nice! I liked the use of *merge* , it seems even more semantic!
--
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
Here's a bit more of playing around at the repl.
clojure.core=> a b
#
#
clojure.core=> (for [[x y] [[a @b] [b @a]]] (swap! x assoc :color (:color y)))
({:color :red} {:color :blu})
clojure.core=> a b
#
#
clojure.core=> (for [[x y] [[a @b] [b @a]]] (swap! x merge y))
({:color :blu} {:color :red})
c
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 mess
yes, that works!
thanks
--
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
Hi,
(defn exchange!
[a b & {:keys [getter setter] {getter identity setter (fn [_ v] v)}}]
(let [av @a bv @b]
(alter a setter (getter bv))
(alter b setter (getter av
(defn exchange-color!
[a b]
(exchange! a b :getter :color :setter #(assoc %1 :color %2)))
(exchange-color! a b)
Yes, that's what I've been doing
What I want to know is if there's a single function that does this exchange
between refs.
--
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
Hi,
a simple let does the trick, no?
(dosync
(let [av @a
bv @b]
(alter a assoc :color (:color bv))
(alter b assoc :color (:color av
Sincerely
Meikel
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send e
Actually this is wrong, I bind the value of the :color of a first, before I
alter b
--
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