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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:05:27+00:00 2026-06-19T01:05:27+00:00

I want to write my own append , for appending an element to an

  • 0

I want to write my own append , for appending an element to an existing list .

I’ve written the following :

(define (appendElem llist elem)
    (if (null? llist)
        elem
        (cons (car llist) (appendElem (cdr llist) elem))))

But when I do this :

(appendElem (list 1 2 30) 11)

I get :

(1 2 30 . 11)

So the question is , why (1 2 30 . 11) and not (1 2 30 11) ?

Thanks

EDIT:

Fixed :

(define (appendElem llist elem)
    (if (null? llist)
        (list elem)
        (cons (car llist) (appendElem (cdr llist) elem))))
  • 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-19T01:05:28+00:00Added an answer on June 19, 2026 at 1:05 am

    Think about what you want your base case to be. Do you want just elem, or do you want a list with the single item elem? There is a difference. If the want the latter, you will need to fix your base case in the code.

    In other words, do you want (appendElem '() 42) to return 42, or (42)? Think carefully about the answer to that question, then think about what the consequence of each choice is.

    By the way, while you can implement appendElem as a toy, you’ll soon realise that that function has O(n) runtime. So do not build lists using this approach! The standard way to build a list is to cons items to it, then reverse the final resulting list.

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

Sidebar

Related Questions

I want to write my own __repr__ for some class that I define. I
I have the following problem. I want to write my own slide show in
I want to write my own locator to access the elements. WebDriver’s API offers
I want to write my own script for comfortable tar-usage (and also become more
I want to write my own script for comfortable tar-usage (and also become more
It comes when I want to write my own quicksort for educational purpose. This
I am embarking on some learning and I want to write my own syntax
I've install subversion, and want to write my own script to automate the web
I have a USB Joystick, and I want to write my own HID driver
I want to write my own port monitor for virtual printer app. Now i

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.