I talked about this a bit on IRC\'s #clojure channel today but would like to go more in detail here. Basically, in order to better understand atoms, swap!
swap!
You could use a macro like:
(defmacro swap!-> [atom & args] `(let [old-val# (atom nil) new-val# (swap! ~atom #(do (swap! old-val# (constantly %)) (-> % ~args)))] {:old @old-val# :new new-val#})) (def data (atom {})) (swap!-> data assoc :a 3001) => {:new {:a 3001} :old {}}