store/[org.clojure/clojure "1.8.0"] clj::clojure.core/compare-and-set!

Official Documentation

Add notes
Arities
==================================================
   [atom oldval newval]

Docstring
==================================================
  Atomically sets the value of atom to newval if and only if the
  current value of the atom is identical 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
  current value of the atom is identical to oldval. Returns true if
  set happened, else false"
  {:added "1.0"
   :static true}
  [^clojure.lang.IAtom atom oldval newval] (.compareAndSet atom oldval newval))

Example 1

Edit
(def a (atom 0))
;; => #'user/a

(compare-and-set! a 10 20)
;; => false

@a
;; => 0

(compare-and-set! a 0 10)
;; => true

@a
;; => 10

Uses on crossclj