Why the function doesn't work?

You have problems, and we're glad to hear them. Explain the problem, what you have tried, and where you got stuck.
Feel free to share a little info on yourself and the course.
Forum rules
Please respect your teacher's guidelines. Homework is a learning tool. If we just post answers, we aren't actually helping. When you post questions, be sure to show what you have tried or what you don't understand.

Why the function doesn't work?

Postby zcohen » Wed Jun 06, 2012 12:56 am

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
zcohen
 
Posts: 6
Joined: Wed Jun 06, 2012 12:41 am

Re: Why the function doesn't work?

Postby Ramarren » Wed Jun 06, 2012 5:08 am

It seems to work. Are you sure you defined the function as included, and not some other version?
Ramarren
 
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland

Re: Why the function doesn't work?

Postby zcohen » Wed Jun 06, 2012 5:17 am

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
zcohen
 
Posts: 6
Joined: Wed Jun 06, 2012 12:41 am


Return to Homework

Who is online

Users browsing this forum: No registered users and 2 guests