When and how often do macro expansions happen in SBCL Common Lisp implementation?

133 Views Asked by At

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.

1

There are 1 best solutions below

0
On BEST ANSWER

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.