1.3.0 permalink 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:4807 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"
   :static true}
  [^clojure.lang.Var v f & args] (.alterRoot v f args))
Vars in clojure.core/alter-var-root:
Used in 0 other vars

Comments top

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