开发者

Do both alter and ref-set update the STM tree in Clojure?

开发者 https://www.devze.com 2023-02-24 08:08 出处:网络
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 in

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!.

0

精彩评论

暂无评论...
验证码 换一张
取 消