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 694701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:53:01+00:00 2026-05-14T02:53:01+00:00

I just started learning Common Lisp a few days ago, and I’m trying to

  • 0

I just started learning Common Lisp a few days ago, and I’m trying to build a function that inserts a number into a tree. I’m getting an error,

*** – SYSTEM::%EXPAND-FORM: (CONS NIL LST) should be a lambda expression

From googling around, it seems like this happens when you have too many sets of parenthesis, but after looking at this for an hour or so and changing things around, I can’t figure out where I could be doing this.

This is the code where it’s happening:

(defun insert (lst probe)
    (cond ((null lst) (cons probe lst))
        ((equal (length lst) 1)
            (if (<= probe (first lst))
                (cons probe lst)
                (append lst (list probe))))
        ((equal (length lst) 2)
            ((cons nil lst) (append lst nil) (insertat nil lst 3)
                (cond ((<= probe (second lst)) (insert (first lst) probe))
                     ((> probe (fourth lst)) (insert (fifth lst) probe))
                     (t (insert (third lst) probe)))))))

I’m pretty sure it’s occurring after the ((equal (length lst) 2), where the idea is to insert an empty list into the existing list, then append an empty list onto the end, then insert an empty list into the middle.

  • 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-05-14T02:53:01+00:00Added an answer on May 14, 2026 at 2:53 am

    Correct! The problem is in the line right after that, where it says

    ((cons nil lst) (append lst nil) (insertat nil lst 3) ...
    

    The issue is the two opening parentheses. Parentheses can change meaning in special contexts (like the cond form you’re using), but in this context, the parentheses signify regular function application, just like you’re probably used to. That means the first thing after the parentheses must be a function. From the perspective of the outer parentheses, the first thing is (cons nil lst), so that must be a function (which it’s not).

    Note that you can’t just remove the parentheses, because the cons function returns a new list like you want but doesn’t change the old list. You probably want something like this:

    (setq lst (cons nil lst))
    (setq lst (append lst nil))
    (setq lst (insertat nil lst 3))
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just started learning Common Lisp--and rapidly falling in love with it--and I've just
I just started learning Lisp and I don't seem to understand the following piece
I've just started learning Obj-C and the Cocoa-Touch framework for developing iPhone and iPad
I just started my own svn server to develop my application. I am learning
I just started learning ruby on rails with Lynda Ruby on Rails 3 Essential
Just started learning how to use paper_clip. I installed everything according the instructions and
Just started learning C from Cocoa developing guide and I was wondering how (if
I just started learning opengl and writing a first person shooter but I'm getting
I just started learning Haskell and I ran into a problem in 2-adic type
I just started learning XSLT,now I am following some on-line tutorial of it,and I

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.