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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:57:55+00:00 2026-05-28T00:57:55+00:00

I want to write a function in lisp that takes two lists of pairs

  • 0

I want to write a function in lisp that takes two lists of pairs and removes all occurrences of the first list from the second list.
As an example, if we have list1 ((a b)(cd)) and list2 ((g h)(a b)(j i)), by calling this function the result would be ((g h)(j i)).

Until now i have the following code (which is not working):

(defun retira(obj l1)
  (cond ((null l1) ())
        ((equal obj (first l1)) (retira obj (rest l1)))
        (t (cons (first l1) (retira obj (rest l1))))))

(defun retira-ocupadas (tabuleiro lista-adj)
  (if (equal (first (todos-ocupados tabuleiro)) (first lista-adj))
    (retira (car (todos-ocupados tabuleiro)) lista-adj))

  (retira-ocupadas (rest (todos-ocupados tabuleiro)) (rest lista-adj))) 

Where retira should remove all occurrences of an object in a list and retira-ocupadas should take care of comparing, if the object from the first list is equal to an object from the second list. Todos-ocupados is a function that generates the first list.

This is currently not working, what am I doing wrong ?

  • 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-28T00:57:56+00:00Added an answer on May 28, 2026 at 12:57 am

    You want to remove any element of the second list that is a member of the first.

    (defun remove-list (list-to-remove target-list)
      (remove-if (lambda (element)
                   (member element list-to-remove
                           :test #'equal))
                 target-list))
    

    Please note the definition of equal, perhaps you want equalp instead (or perhaps you need to write your own pair-equal).

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

Sidebar

Related Questions

I want to write a function that takes items from a list and groups
I want to write a function in lisp that reverses all elements from the
I want to write a function that iterates through a list, but takes two
I want to write a function that takes an array of letters as an
I want to write a function that accepts two objects as parameters and compare
I want to write 'twice' function that takes a function and an argument and
I want to write a function that takes an int between 1 and 64,
i want to write a function that checks for equality of lists in SML
I want to write a function that splits lists into sublists according to what
I want to write a function in Python that returns different fixed values based

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.