macro | since v0.0-927 | clojure.core/binding | Edit |
(binding bindings & body)
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.
(def ^:dynamic *foo* 1)
(defn do-something []
(println *foo*))
(binding [*foo* 2]
(do-something))
;;=> prints 2
*foo*
;;=> 1
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.
(core/defmacro binding
[bindings & body]
(core/let [names (take-nth 2 bindings)]
(cljs.analyzer/confirm-bindings &env names)
`(with-redefs ~bindings ~@body)))