Skip to content

Instantly share code, notes, and snippets.

@benatkin
Created May 7, 2009 05:12
Show Gist options
  • Save benatkin/107930 to your computer and use it in GitHub Desktop.
Save benatkin/107930 to your computer and use it in GitHub Desktop.
; the binding macro ought to be handy for implementing something like fakeweb or timecop in Clojure
(def x 9)
(defn printx [] (println x))
(printx) ; prints 9
(binding [x 5] (printx)) ; prints 5
(printx) ; prints 9
(defn say-hi [] (println "Hi!"))
(defn say-hi-twice [] (dotimes [n 2] (say-hi)))
(say-hi-twice) ; prints "Hi!" twice
(binding [say-hi (fn [] (println "Howdy!"))] (say-hi-twice)) ; prints "Howdy!" twice
(say-hi-twice) ; prints "Hi!" twice
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment