Do both alter and ref-set update the STM tree in Clojure?
I am using refs everywhere in my Clojure code and then I realised I was using ref-set
everywhere. Does this destroy the history of changes in the STM? Or should I be using alter
only and ref-set
to intialise the ref?
I am not sure if the difference is merely syntactical and alter开发者_Go百科
ends up calling ref-set
anyway. Can someone enlighten me?
(alter aref f arg1 ... argn)
is basically the same as
(ref-set aref (f @aref arg1 ... argn))
Similar for atoms with reset!
and swap!
.
精彩评论