You're viewing version 1.2.0 of atom. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16
  • (atom x)
  • (atom x & options)
Creates and returns an Atom with an initial value of x and zero or
more options (in any order):

:meta metadata-map

:validator validate-fn

If metadata-map is supplied, it will be come the metadata on the
atom. validate-fn must be nil or a side-effect-free fn of one
argument, which will be passed the intended new state on any state
change. If the new state is unacceptable, the validate-fn should
return false or throw an exception.

1 Example top

  • user=> (def my-atom (atom 0))
    #'user/my-atom
    
    user=> @my-atom
    0
    
    user=> (swap! my-atom inc)
    1
    
    user=> @my-atom
    1
    
    user=> (swap! my-atom (fn [n] (* (+ n n) 2)))
    4
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:1767 top

(defn atom
  "Creates and returns an Atom with an initial value of x and zero or
  more options (in any order):

  :meta metadata-map

  :validator validate-fn

  If metadata-map is supplied, it will be come the metadata on the
  atom. validate-fn must be nil or a side-effect-free fn of one
  argument, which will be passed the intended new state on any state
  change. If the new state is unacceptable, the validate-fn should
  return false or throw an exception."
  {:added "1.0"}
  ([x] (new clojure.lang.Atom x))
  ([x & options] (setup-reference (atom x) options)))
Vars in clojure.core/atom: defn

Comments top

No comments for atom. Log in to add a comment.