Reputation: 2711
Some Lisp implementations (i) expand macros once and save the result for reuse; (ii) others reexpand the macro at each macro call. Some implementations (iii) even attempt to expand macro calls in function bodies at the time the function is DEFUNed.
Which one is the case for SBCL?
Thanks.
Upvotes: 2
Views: 137
Reputation: 139411
in the REPL:
* (defparameter *expansions* 0)
*EXPANSIONS*
* (defmacro foo ()
(incf *expansions*)
(print (list :expansions *expansions*))
nil)
* (foo)
(:EXPANSIONS 1)
NIL
* (defun bar () (foo))
(:EXPANSIONS 2)
BAR
* (bar)
NIL
*
So there is one expansion for a function definition and none at runtime of that function.
Then one might try the file compiler, an interpreter, different debug options, etc. to check the number of macro expansions done by an implementation.
Upvotes: 3