Once upon a time I was playing with macros and came up with this:
(defmacro my-recursive-fact (n)
(if (= 0 n) '1
(let ((m (1- n)))
`(* ,n (my-recursive-fact ,m)))))
And it worked.
CL-USER> (my-recursive-fact 5)
120
So then I thought it could be a nice way to show students an example of recursion, if I expand this macro using macroexpand
:
CL-USER> (macroexpand '(my-recursive-fact 5))
(* 5 (MY-RECURSIVE-FACT 4))
T
That is, no difference between macroexpand-1
and macroexpand
in this case. I'm sure that I'm missing some crucial point in understanding macroexpand
, and HyperSpec says nothing special about recursive macros.
And also I'm still curious to know if there is a way to expand such kind of macro to it's end.