fork download
  1.  
  2. (def static-scoped 21)
  3. (def ^:dynamic dynamic-scoped 21)
  4.  
  5. (defn some-function []
  6. (println "static = " static-scoped)
  7. (println "dynamic = " dynamic-scoped))
  8.  
  9. (defn other-function []
  10. (binding [dynamic-scoped 42]
  11. (println "Established new binding in dynamic environment")
  12. (some-function)))
  13.  
  14.  
  15. ;; Trying to establish a new binding for the static-scoped
  16. ;; variable won t affect the function defined
  17. ;; above.
  18. (let [static-scoped 42]
  19. (println "This binding won't affect the variable resolution")
  20. (other-function))
  21.  
  22. (println "calling some-function directly")
  23. (some-function)
Success #stdin #stdout 1.95s 335552KB
stdin
Standard input is empty
stdout
This binding won't affect the variable resolution
Established new binding in dynamic environment
static =  21
dynamic =  42
calling some-function directly
static =  21
dynamic =  21