Hi,
This is trivial question.
Which style do you like?
(def *counts* (ref {}))
(defn dec-or-dissoc! [key]
(dosync
(let [n (@*counts* key)]
(if (< 1 n)
(alter *counts* assoc key (dec n))
(alter *counts* dissoc key)))))
(defn dec-or-dissoc! [key]
(dosync
(alter *counts*
(fn [m]
(let [n (m key)]
(if (< 1 n)
(assoc m key (dec n))
(dissoc m key)))))))
I think former style is normal, but latter is easy to replace ref with
atom.
Thanks.
--
Takahiro Hozumi
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
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