binding

macrosince v0.0-927 clojure.core/bindingEdit
(binding bindings & body)

Details:

binding => var-symbol init-expr

Creates new bindings for the (already-existing) vars, with the supplied initial values, executes the exprs in an implicit do, then re-establishes the bindings that existed before.

The new bindings are made in parallel (unlike let); all init-exprs are evaluated before the vars are bound to their new values.


Examples:

(def ^:dynamic *foo* 1)

(defn do-something []
  (println *foo*))

(binding [*foo* 2]
  (do-something))
;;=> prints 2

*foo*
;;=> 1

See Also:


Source docstring:
binding => var-symbol init-expr

Creates new bindings for the (already-existing) vars, with the
supplied initial values, executes the exprs in an implicit do, then
re-establishes the bindings that existed before.  The new bindings
are made in parallel (unlike let); all init-exprs are evaluated
before the vars are bound to their new values.
Source code @ clojurescript:src/main/clojure/cljs/core.cljc
(core/defmacro binding
  [bindings & body]
  (core/let [names (take-nth 2 bindings)]
    (cljs.analyzer/confirm-bindings &env names)
    `(with-redefs ~bindings ~@body)))