Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8049013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:39:44+00:00 2026-06-05T06:39:44+00:00

I have this function in LISP with regular parameter and optional paremater n: (defun

  • 0

I have this function in LISP with regular parameter and optional paremater n:

(defun lastplus (x &optional (n 0)) //default value for n is 0
    ( if (listp x) //if x is a list
        (
            (list (length x) (n)) //return list that contains length(x) and n
        )
        (n) //else return n
    )
)

I am trying to use the function in the listener file but it gives me this error:

CL-USER 13 : 4 > (lastplus 2 8) 

Error: Undefined function N called with arguments ().

I use LispWorks 6.0.1

Do you know why do I get this error?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T06:39:45+00:00Added an answer on June 5, 2026 at 6:39 am
    (defun lastplus (x &optional (n 0)) //default value for n is 0
        ( if (listp x) //if x is a list
            (
                (list (length x) (n)) //return list that contains length(x) and n
            )
            (n) //else return n
        )
    )
    

    Your formatting style is not Lispy.

    Adapt to Lisp formatting:

    (defun lastplus (x &optional (n 0)) ; default value for n is 0
       (if (listp x) ; if x is a list
            ((list (length x) (n))) ; return list that contains length(x) and n
         (n)))
    

    You said: cannot call function with optional parameter.

    Sure you can. The error message did say something else. You can call a function with an optional parameter. The error is inside the function.

    The error says: Error: Undefined function N called with arguments ().

    So you are calling a function called N, which does not exist. With no arguments. Like in (n). Check your code – can you find (n)?

    Now ask yourself:

    • What does a function call look like?

    • Answer: open parenthesis, function, possibly some arguments, closing parenthesis

    • What does (n) look like?

    • Answer: it looks like a function call.

    • Is that what you wanted?

    • Certainly not.

    • What did you want?

    • The variable value.

    • What does that look like?

    • just n.

    • Are there other errors?

    • Hmm.

    • What about the form on the third line?

    • That looks wrong, too.

    • It’s wrong, too. Same error..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this function (defun mention-notify (match-type nickuserhost msg) (interactive) (if (and (eq match-type
Say I have a function that takes a list and does something: (defun foo(aList)
I have this function, I need to store some values in an array, I
I have this function in my PHP : setcookie(UserPusser, $user, time() + 604800, /pusser/beta/);
I have this function below and I need to append its result inside a
I have this function call passed as a string: var dcall = tumbsNav(1); Is
I have this function that is storing the contents of an array in three
i have this function to get the index key of an element in $clientsObjects
I have this function which writes content to a text file: function write($text){ fwrite($this->fp,
I have this function which cuts a string into a number of characters without

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.