Created
October 3, 2013 16:39
-
-
Save kingcons/6812896 to your computer and use it in GitHub Desktop.
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
(defmacro count-macro-expansions (&body body) | |
"Count the number of macro expansions required to execute | |
BODY. Return two values: the result of executing BODY and the | |
number of expansions." | |
(let ((closures (gensym "CLOSURES-"))) | |
`(let* ((,closures | |
(funcall | |
(compile nil | |
`(lambda () | |
(let ((count 0)) | |
(cons (lambda (expander form env) | |
(incf count) | |
(funcall expander form env)) | |
(lambda () count))))))) | |
(*macroexpand-hook* (car ,closures))) | |
(values (progn ,@body) | |
(funcall (cdr ,closures)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment