Last active
July 20, 2020 18:17
-
-
Save Solaxun/70a06643b990b4075a41bb2eb27d7426 to your computer and use it in GitHub Desktop.
At runtime, the function created by the macroexpansion captures lexical scope from wherever it's called, and is stored in the atom.
This file contains 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 protos (atom nil)) | |
(defn build-func [[name args body]] | |
(list 'fn name args body)) | |
(defmacro bleh [fbody] | |
`(let [f# ~(build-func fbody)] | |
(do (reset! protos f#) f#))) | |
(macroexpand-1 '(bleh (foo [y] (+ x y)))) | |
(let [x 100 | |
func (bleh (foo [y] (+ x y)))] | |
(func 15)) | |
;; closure created above stored in atom (i.e. protocol map) | |
(@protos 80) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment