Clojure has an immutable data model. However, this doesn't mean that we can't represent data and change it over time. Direct change or mutation should be avoided at all costs. If necessary, a
binding macro will create new
var values (or bindings) that are local only to a
binding context or scope. These Vars must be marked as
^:dynamic and they should already exist:
(def ^:dynamic a 1) (def ^:dynamic b 2) (binding [a 10 b 20] (+ a b)) ; => 30 a ; => 1 b ; => 2
It is, however, preferable to choose one of four reference types: Var, Atom, Agent, and Ref. Doing this requires an understanding of Clojure's notion of identity, value, and time. In his presentation Are We There Yet? (you can read more at http://www.infoq.com/presentations/Are-We-There-Yet-Rich-Hickey ...