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 ) )
)
)
```

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