I'd say the former was more idiomatic Clojure. There's no need to make refs compatible with atoms (otherwise why have two different concurrency primitives in the first place).
Additionally, earmuffs (like *this*) should only be used on vars that you expect to override in a binding, like *out* or *err*. They aren't for all global vars. You should rename "*counts*" to just "counts". - James On 28 November 2010 22:36, Takahiro Hozumi <fat...@googlemail.com> wrote: > 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 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