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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:49:31+00:00 2026-05-17T23:49:31+00:00

While attempting to generate a list of subsets that exist within two sets, I

  • 0

While attempting to generate a list of subsets that exist within two sets, I am running into an issue with cons. A procedure takes in a list named result and attempts to construct a new list out of result and the car of another set. So far, the set is generated with the correct elements, but they are contained within a size N nested list, where N is the number of nestings and the number of elements within the subset for which I am searching.

How can I apply cons with result without creating a nested list?

Example:

;These are two sets that I will be checking
(define s1 '(1 2 3 4))
(define s2 '(1 2 3))
;Result from running these lists through my procedure
(((() . 1) . 2) . 3)
;What I want to have generated
(1 2 3)

I need to be able to call (car list) and receive 1 not ((() . 1) . 2)

  • 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-17T23:49:31+00:00Added an answer on May 17, 2026 at 11:49 pm

    First of all (((() . 1) . 2) . 3) is not a nested list – it’s not a list at all. (((() 1) 2) 3) would be a nested list. (((() . 1) . 2) . 3) is a dotted pair whose first element is also a dotted pair.

    So now to explain the behaviour you see: In the lisp family of languages (cons a b) creates a pair containing a as it’s car and b as its cdr.

    Now a list is either the empty list (()) or a pair whose cdr is also a list (the car might contain anything – if both the cdr and the car are a list, the list is called a nested list).

    A pair that is not a list is called a dotted pair. This what you’re creating here because you’re calling cons with a second argument which is not a list.

    Conclusion:

    You can not use cons to append to the end of the list. If you need to append to the end of a list, you can use concat with a single-element list as the second argument.

    Note however that appending to the end of a list, is an O(n) operation while appending at the front (using cons) is an O(1) operation, so if possible you should change your algorithm, so it only needs to append at the front.

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

Sidebar

Related Questions

I am attempting to programmatically generate javadocs via an instance of Runtime through the
While attempting to send a message for a queue through the BeginSend call seem
mWhile attempting to make a backup copy of a file in C, I find
I'm attempting to solve the second problem on Project Euler, here is the problem:
I'm attempting to plot an iterative function in OpenGL ES. An array of ints
To restore a database data and log files to different drives I am running
I have an ASP.NET 3.5 app with a SQL 2005 Express .mdf database file
How does one use MPI_Comm_spawn to start worker processes on remote nodes? Using OpenMPI
I have started learning WCF. I wrote a simple service to query a SQL

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.