• 13
• 18
• 19
• 27
• 9

# Lisp macro error

This topic is 3892 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

To any Common Lispers out there: I have the following macro defined in Clisp
(defmacro fac (n)
(if (= n 0) 1 (* n (fac (- n 1)))))

Obviously, this could just as easily be a function, but I was curious to see what would happen if I defined a macro like this. In any case, I get the following whenever I try to call (fac 5)
(- N 1) is not a number (SIMPLE-TYPE-ERROR)

Does anyone know what might be causing this? I've seen both recursive macros and macros without any backquotes, so I'm not sure what the problem is.

##### Share on other sites
When invoking a macro, its arguments are not evalated. Thus, the part at the end that reads (fac (- n 1)) calls fac with n = '(- n 1) which is obviously mal-formed (because it is a list and not a number).