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

  • Home
  • SEARCH
  • 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 6719431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:05:32+00:00 2026-05-26T09:05:32+00:00

I have an implementation of a function called modify list shown below but it

  • 0

I have an implementation of a function called modify list shown below but it only works for top level lists.

(defun modify-list (old new a-list)
  (cond
   ((null a-list) nil)
   ((eql (car a-list) old) (cons new (modify-list old new (cdr a-list))))
   (T (cons (car a-list)(modify-list old new (cdr a-list))))))

CL-USER 16 : 6 > (modify-list ‘a ‘x ‘(p a d g c a))
(P X D G C X) <– GOOD!

CL-USER 17 : 6 > (modify-list ‘a ‘x ‘(p a d (g a) c a))
(P X D (G A) C X) <—-NOT GOOD!

can anyone help me make this function work on nested lists?

  • 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-26T09:05:33+00:00Added an answer on May 26, 2026 at 9:05 am

    Why not working at an higher level? It would make the code simpler…

    (defun modify (old new x)
      (cond
        ((eq x old) new)
        ((listp x)
         (mapcar (lambda (y) (modify old new y)) x))
        (t x)))
    

    Basically instead of assuming x must be a list (actually a tree) you just return new if x is old, recursively map if it’s a list or otherwise return x unchanged…

    With this approach also (modify 'a 'x 'a) --> X (and that IMO seems right).

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

Sidebar

Related Questions

I know that it's OK for a pure virtual function to have an implementation.
I have seen that a prime number implementation of the GetHashCode function is being
I have a simple html multiline tooltip implementation: this.tooltip = function(tag) { xOffset =
LINQ library in .NET framework does have a very useful function called GroupBy ,
How can I ensure my table data function is called only once when app
I have a subprocess function (called parseContents) that gets called using the following code:
So I have a function called find, which has two versions: template <typename T>
I have a working implementation of NDK library and corresponding Java-class. But I am
I downloaded the JSON2.js from https://github.com/douglascrockford/JSON-js/blob/master/json2.js and it does not have implementation for JSON2.stringify()
I have an implementation of default handler. When it gets to a   in

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.