Created
July 6, 2016 13:46
-
-
Save skatenerd/fb3d4fe71792ff038b12606605fb678b to your computer and use it in GitHub Desktop.
some code @trptcolin wrote to help me understand macros
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def x (atom 1)) | |
(defmacro foo [] | |
(let [times @x | |
prints (map (fn [_] `(println "hello world")) (range times))] | |
`(do ~@prints))) | |
(defn foo-caller [] (foo)) | |
; will the output change or stay the same? | |
; it stays the same because macroexpansion happened when foo-caller was defined | |
(swap! x inc) | |
(foo-caller) | |
(swap! x inc) | |
(foo-caller) | |
(swap! x inc) | |
(foo-caller) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment