You're viewing version 1.2.0 of alter-var-root. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16

alter-var-root

clojure.core

  • (alter-var-root v f & args)
Atomically alters the root binding of var v by applying f to its
current value plus any args

1 Example top

  • (defn sqr [n] 
      "Squares a number"
      (* n n))
    
    user=> (sqr 5)
    25
    
    user=> (alter-var-root 
             (var sqr)                     ; var to alter
             (fn [f]                       ; fn to apply to the var's value
               #(do (println "Squaring" %) ; returns a new fn wrapping old fn
                    (f %))))
    
    user=> (sqr 5)
    Squaring 5
    25
    
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:4347 top

(defn alter-var-root
  "Atomically alters the root binding of var v by applying f to its
  current value plus any args"
  {:added "1.0"}
  [^clojure.lang.Var v f & args] (.alterRoot v f args))
Vars in clojure.core/alter-var-root: defn

Comments top

No comments for alter-var-root. Log in to add a comment.