let creates a lexically modified alias for some value. binding creates a dynamic-binding binding for some Var .
Dynamic binding means that the code inside your binding form and any code that calls this code (even if not in the local lexical area) will see a new binding.
Given:
user> (def ^:dynamic x 0)
binding actually creates a dynamic binding for Var , but let only a shadow of var with a local alias:
user> (binding [x 1] (var-get #'x)) 1 user> (let [x 1] (var-get #'x)) 0
binding can use qualified names (since it works on Var s) and let cannot:
user> (binding [user/x 1] (var-get #'x)) 1 user> (let [user/x 1] (var-get #'x)) ; Evaluation aborted. ;; Can't let qualified name: user/x
let integrated bindings are not changed. binding integrated bindings change by type:
user> (binding [x 1] (set! x 2) x) 2 user> (let [x 1] (set! x 2) x) ; Evaluation aborted. ;; Invalid assignment target
Lexical and dynamic linking:
user> (defn foo [] (println x))
See also Vars , let .
Brian Carper Oct 06 '09 at 3:00 2009-10-06 03:00
source share