Edit: this will break if there is a variable in the operatorโs special design whose name matches the macro name in the carโs position of the form. For example: (let ((setf 10)) (print setf))
This is pretty old, but if someone who came across this question wished there was some kind of portable way to recursively expand macros:
(defun recursive-macroexpand (form) (let ((expansion (macroexpand form))) (if (and (listp expansion) (not (null expansion))) (cons (car expansion) (mapcar
E.G. (tested in SBCL and CLISP):
(recursive-macroexpand '(my-recursive-fact 5)))) => (* 5 (* 4 (* 3 (* 2 (* 1 1)))))
A more ugly example (a regular macroexpand would leave the second dolist unchanged):
(recursive-macroexpand '(dolist (x '(0 1)) (dolist (y '(0 1)) (format t "decimal: ~a binary: ~a~a~%" (+ (* x 2) (* y 1)) xy)))) => (block nil (let* ((#:list-8386 '(0 1)) (x nil)) nil (tagbody
source share