Page 1 of 1

Why the function doesn't work?

Posted: Wed Jun 06, 2012 12:56 am
by zcohen
Hi everybody,
I have this function that gets 2 parameters - one of them is optional. It does this:
if x is an empty list or not a list return the optional parameter.
else - return a list that contains length(x) and list of last value of x and the optional parameter.
This is the function:

Code: Select all

(defun lastplus (x &optional (n 0)) ; n is optional parameter with default value of 0
	( if (or (not (listp x)) (null x))
                n
		(list (length x) (list (nth (- (length x) 1 ) x )  n ) )
	)
) 
I loaded the function to the Listener, but it gives me this error:
CL-USER 2 : 1 > (lastplus 2)
Error: Undefined function N called with arguments ().

I can't understand what am I doing wrong. Could you guys help me?
About me:
I am a student at JCT Jerusalem high college of technology.

thanks

Re: Why the function doesn't work?

Posted: Wed Jun 06, 2012 5:08 am
by ramarren
It seems to work. Are you sure you defined the function as included, and not some other version?

Re: Why the function doesn't work?

Posted: Wed Jun 06, 2012 5:17 am
by zcohen
Ramarren wrote:It seems to work. Are you sure you defined the function as included, and not some other version?
It actually works. For some reason, It worked only when I copied the function to a new .lisp file.
Thanks anyway