Skip to content

Instantly share code, notes, and snippets.

@pete
Created April 2, 2009 19:46
Show Gist options
  • Save pete/89390 to your computer and use it in GitHub Desktop.
Save pete/89390 to your computer and use it in GitHub Desktop.
; This is how you simulate dynamic scoping in Clojure (as far as I can
; tell):
(defn print-foo [] (println foo)) ; -> #'user/print-foo
; Now, try calling print-foo from both a let and a binding:
(let [foo "let foo"] (print-foo))
; 10
(binding [foo "bound foo"] (print-foo))
; bound foo
; In Roboto, if you wanted to do this but didn't want to use a macro,
; you'd do this:
; The prep work:
(= foo "oh noes")
(def print-foo () (puts foo))
; Yes, it prints "oh noes\n".
(print-foo)
; oh noes
; And does the same thing if called from a different binding:
(bind (foo "bound!") (print-foo))
; oh noes
; But you can re-bind a function:
(enclose print-foo (bind (foo "this one works")))
(print-foo)
; this one works
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment