Skip to content

Instantly share code, notes, and snippets.

@skatenerd
Created July 6, 2016 13:46
Show Gist options
  • Save skatenerd/fb3d4fe71792ff038b12606605fb678b to your computer and use it in GitHub Desktop.
Save skatenerd/fb3d4fe71792ff038b12606605fb678b to your computer and use it in GitHub Desktop.
some code @trptcolin wrote to help me understand macros
(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