Alex Rivera | Logout

How is my LISP function an unbound variable?

Asked 2010-08-31T01:28:35.617
10

I define a function in LISP, and it defines correctly. But whenever I try to call it, I get an error saying "The variable FACTORIAL is unbound."

I have tried this on both OS X and Windows 7, on LispWorks and Allegro. The function is -

(defun factorial (x)
   (if (= 1 x) 1
       (* x factorial (- 1 x))))

Any help is appreciated.

Edit
Report

1 Answer

5

It looks like you're missing a set of parentheses:

(defun factorial (x) 
   (if (= 1 x) 1 
       (* x (factorial (- 1 x))))) 

Without the () around factorial, Lisp thinks you're referring to a variable instead of a function.

answered 2010-08-31T01:33:00.990

Your Answer