(compare-and-set! a oldval newval)
Atomically sets the value of atom to newval if and only if the
current value of the atom is equal to oldval. Returns true if
set happened, else false.
Source
(defn
compare-and-set!
"Atomically sets the value of atom to newval if and only if the\n current value of the atom is equal to oldval. Returns true if\n set happened, else false."
[a oldval newval]
(if (= (-deref a) oldval) (do (reset! a newval) true) false))