I am very new to lisp, and am having a hard time even getting my feet wet. I'm sure once, I have a few functions working, I'll be able to build upon them and work on higher order functions, and more complex problems.
Can someone point out my errors in the following code.
(defun indeHelper(A L N)
(cond (Null N) nil)
((= A (first L) (cons N (indeHelper A (rest L) (+ 1 N)))))
(t (indeHelper A (rest L) (+ 1 N))))
(defun inde(A L)
(funcall indeHelper(A L 1)))
Also how would I call this? I have one function I think is working ok, but I can't get the syntax for calling it. Thanks for any help.
You have a number of syntax issues.
The syntax of
COND
is:Your
test1
is supposed to be(null n)
, andbody1
should benil
, but you didn't wrap them in a level of parentheses. Then your other tests and bodies are outsidecond
, as should be apparent from the indentation.It should be:
In the second function, you don't need to use
funcall
. That's used when you're calling a dynamically-determined function (e.g. when writing higher-order functions), but you're just calling a known function. It should just be:If you did need to use
funcall
, the syntax is:When using
funcall
, the arguments aren't put into a nested list, they're just ordinary arguments tofuncall
.