yazz.com
yazz.com

Reputation: 58786

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 ends up calling ref-set anyway. Can someone enlighten me?

Upvotes: 1

Views: 209

Answers (1)

kotarak
kotarak

Reputation: 17299

(alter aref f arg1 ... argn)

is basically the same as

(ref-set aref (f @aref arg1 ... argn))

Similar for atoms with reset! and swap!.

Upvotes: 4

Related Questions