I keep getting random errors when compiling this function:
(defun gcd (a b)
(if (= b 0)
a
(gcd b mod (a b))))
The most common is that it says "undefined function a." So I figured I needed return a in that place. This did not work. I get a to many parameters for if statement error. Any idea what I am doing wrong here? New to Lisp and so far we are not seeing eye to eye.
Running on CLISP on Windows 7.
(gcd b mod(a b))
should be(gcd b (mod a b))
You
mod
function call is wrong. Here's my working code:Usually a compiler can give you more information:
Using LispWorks:
So you see that you call
GCD1
with the wrong number of arguments, thatMOD
is assumed to be a variable and thatA
is assumed to be a function.SBCL:
In Lisp a function call always* starts with '(', so the line
means "call the function
gcd
with argumentsb
,mod
and the result of calling functiona
with argumentb
".I suspect you really want something like:
*I haven't used Lisp for a little while so I might not be 100% correct on the "always".