Alternate version of swap! also returning swapped out value

后端 未结 5 794
栀梦
栀梦 2021-01-20 03:33

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!

5条回答
  •  无人共我
    2021-01-20 04:21

    If you want the return value, Stuart answer is the correct one, but if you are just going to do a bunch of println to understand how atoms/refs work, I would recommend to add a watch to the atom/ref http://clojuredocs.org/clojure_core/1.2.0/clojure.core/add-watch

    (add-watch your-atom :debug (fn [_ _ old new] (println "out" old "new" new)))
    

提交回复
热议问题