This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

Why the function doesn't work?

3 posts · 3790 views

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:
(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?

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?

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