ClojureDocs

Nav

Namespaces

Assignment special form. When the first operand is a field member access
form, the assignment is to the corresponding field. If it is an instance
field, the instance expr will be evaluated, then the expr. In all cases
the value of expr is returned. Note - you cannot assign to function params
or local bindings. Only Java fields, Vars, Refs and Agents are mutable in
Clojure. See http://clojure.org/special_forms for more information.
4 Examples
(set! var-symbol expr)
(set! *warn-on-reflection* true)
user=> (let [object (java.awt.Point. 1 2)]
        (set! (. object  -y) 8)
        (bean object)
        )
{:class java.awt.Point, :location #object[java.awt.Point 0x383fc59b "java.awt.Point[x=1,y=8]"], :x 1.0, :y 8.0}
;; A mutable (and thread unsafe) Counter class.
;; set! is used to mutate the internal cnt attribute.

(deftype Counter [^:unsynchronized-mutable cnt]
  clojure.lang.IFn
  (invoke [this] (set! cnt (inc cnt))))

(def counter (->Counter 0))
(counter) ;; 1
(counter) ;; 2
See Also

Sets the value of atom to newval without regard for the current value. Returns newval.

Added by AtKaaZ

binding => var-symbol init-expr Creates new bindings for the (already-existing) vars, with the ...

Added by AtKaaZ

Atomically alters the root binding of var v by applying f to its current value plus any args

Added by AtKaaZ

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

Added by MicahElliott
1 Note