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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:00:10+00:00 2026-05-26T22:00:10+00:00

This is probably a simple thing I’m missing, but I’m trying to get the

  • 0

This is probably a simple thing I’m missing, but I’m trying to get the cdr of a pair and every call to say (cdr (cons 'a '5)) comes back as (5). I sort of get why that is, but how can I get the it to return without the parens?

I don’t want to use flatten because what I’m trying to get (i.e. the cdr) might itself be another procedure expression already wrapped in parens, so I don’t want to flatten the list.

(If it matters, I’m working on transforming a let expression into a lambda expression, and this is one of the steps I’m taking, trying to break apart the lambda bindings so I can move them around).

  • 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-26T22:00:11+00:00Added an answer on May 26, 2026 at 10:00 pm

    When applied to a proper list, cdr will always return another list (including '(), the empty list).

    With proper list I mean a list which ends with the empty list. For instance, when you do this (define lst '(4 5)) under the hood this is what gets assigned to lst: (cons 4 (cons 5 '())), so when you evaluate (cdr lst) you get the second element of the first cons, which happens to be (cons 5 '()), which in turn gets printed as (5).

    For extracting only the second element in the list (not the second element of the first cons, which is what cdr does) you could:

    1. As has been pointed in the comments, use (car (cdr lst)) or just (cadr lst) for short
    2. Even simpler: use (second lst)
    3. Another possibility – if the list only has two elements and it’s ok to replace it with an improper list, use (define cell (cons 4 5)) or (define cell '(4 . 5)) to build a cons cell and then you can use (car cell) to extract the first element and (cdr cell) to extract the second element.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably pretty simple, but here: Say I've got two models, Thing and
This is probably a really simple thing, but I haven't been able to find
This is probably a simple thing, but ive got the following code: <div> @using
This is probably a really simple thing, but I don't know how to implement
This is probably a simple thing. I'm trying to draw my first shapes in
I know this probably really simple but Im not sure what im doing wrong...
This probably has a simple answer, but I must not have had enough coffee
This is probably a simple answer but I can't find it. I have a
This is probably a simple question but I am not an ASP.NET developer and
This is probably a simple question, and I'm slightly embarrassed to ask it, but

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.