Pedro Delfino
Pedro Delfino

Reputation: 2711

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

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

Answers (1)

Rainer Joswig
Rainer Joswig

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

Related Questions