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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:49:22+00:00 2026-06-12T17:49:22+00:00

I write two program one is to takeoutAllButLast , other is takeoutSecondLast. I initially

  • 0

I write two program one is to takeoutAllButLast , other is takeoutSecondLast.

I initially use the member function to determine whether there is more X behind.

And I try some data and find that:

If the first argument is a symbol, they both work!

But if it is cons structure, they both fail.

1.// `(a b)   `((b b)(a b)(b c)(a b)) ==>  `((b b)(b c)(a b)) 

(defun takeoutAllButLast (X L)
(cond ((null L) nil)
       ((equal X (first L)) 
           (if (member X (rest L)) 
               (takeoutAllButLast X (rest L)) 
               L)) 
       (t (cons (first L) (takeoutAllButLast X (rest L))))
)
)

2.//`(a b)   `((a b)(b b)(a b)(b c)(a b)) ==>  `((a b)(b b)(b c)(a b)) 
(defun takeoutSecondLast (X L)
(cond ((null L) nil)
       ((equal X (first L)) 
           (if (member X (rest (member X (rest L))))
    (cons (first L) (takeoutSecondLast X (rest L)))
    (rest L)
           )
    )
   (t (cons (first L) (takeoutSecondLast X (rest L))))
 )

What I want to ask is how to determine whether there is still one element is X behind, and can be used like member function?

And why member function cannot be used to compare cons structure?

Thx for you reading my question!

  • 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-12T17:49:23+00:00Added an answer on June 12, 2026 at 5:49 pm

    member defaults to using eql as its equality predicate. That works fine on symbols, numbers and a few other things (that is (eq 'a 'a) is always true, (let ((cons (cons 'a 'a))) (eql cons cons)) is always true, but (eql (cons 'a 'a) (cons 'a 'a)) is almost never true).

    You can pass an alternative equality checker to member using the :test keyword and if you use #'equal you will (probably) get what you want.

    If you want to call member with the custom equality checker foo, simply do:

    (member thing-to-check-for the-list-to-check :test #'foo)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a program to automate one of my more boring and
I'm trying to write a program that merge two or more .dat files in
I wanted to write a program that test if two files are duplicates (have
i have been trying to write a program in python to read two text
I'm trying to write a basic synchronisation program to copy files between two directories.
I write two function, which callback will be invoke by the fn : var
suppose we have two numbers i want write program which print common bits subsequent
The question is to write two solutions to the quadratic formula. One result is
I have homework that should use fork() and wait() system calls: 1) Write two
I have a program that XORs two files together using one time pad encryption.

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.