The documentation for Clojure with-local-vars and with-bindings doesn't suffice for me to distinguish the two. Any hints?
Difference between with-local-vars and with-bindings in Clojure
1.3k Views Asked by Reb.Cabin At
2
There are 2 best solutions below
0
On
(with-bindings) expects the keys of the bindings map to be Vars, not symbols. It pushes the given map of var/values onto the stack of thread local bindings and take care to remove it after the given function returned. It is a low level function.
(with-local-vars) allows you to code in imperative style (mutating state).
New
vars are temporarily created bywith-local-vars. Existingvars are temporarily rebound bywith-bindings. In both cases the bindings are thread-local.Note that
with-bindingsis, as far as I can tell, primarily useful as a helper to pass bindings from another context by using a map returned byget-thread-bindings. The similar functionbindingwould be more typical when not importing bindings.Illustrative examples: