Jump to content
  • Advertisement
Sign in to follow this  
Captain_Thunder

Lisp macro error

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!