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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:11:25+00:00 2026-05-15T17:11:25+00:00

Below is my code which takes a car element of a list (carVal) and

  • 0

Below is my code which takes a car element of a list(carVal) and an list(initialized to empty) as parameters. I want to append the element to the list but the same is not working.

(define populateValues
   (lambda (carVal currVal)
      (append currVal(list carVal ))
       (display currVal)))

The display shows empty list all the time () . Can anyone help me understand why?

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

    Well, there is append! as a primitive, which solves most of your problems, as noted already, Scheme tends to frown on mutation, it is possible, but typically avoided, so all procedures that mutate have a ! (called a bang) at their end.

    Also, set! does not mutate data, it changes an environment, it makes a variable point to another thing, the original data is left unchanged.

    Mutating data in Scheme is quite cumbersome, but, to give you my own implementation of append! to see how it is done:

    (define (append! lst . lsts)
      (if (not (null? lsts))
          (if (null? (cdr lst))
              (begin
                (set-cdr! lst (car lsts))
                (apply append! (car lsts) (cdr lsts)))
              
              (apply append! (cdr lst) lsts))))
    

    Note the use of set-cdr!, which is a true mutator, it only works on pairs, it mutates data in memory, unlike `set!’. If a pair is passed to a function and mutated with set-cdr! or set-car!, it is mutated every-where in the program.

    This obeys the SRFI append! spec which says that it should be variadic and that it should return an undefined value, for instance.

    (define l1 (list 1 2 3 4))
    
    (define l2 (list 2 3 4))
    
    (define l3 (list 3 1))
    
    (append! l1 l2 l3)
    
    l1
    
    l2
    
    l3
    

    Which displays:

    (1 2 3 4 2 3 4 3 1)
    (2 3 4 3 1)
    (3 1)
    

    As visible, append! can take an infinite number of arguments and it mutates them all but the last.

    Scheme might not be the ideal language for you though. The use of append! as said before is nonstandard, instead, append is preferred, which does not mutate and is called for its return value. Which I implement as such:

    (define (append . lsts)
      (cond
        ((null? lsts) '())
        ((null? (car lsts)) (apply append (cdr lsts)))
        (else (cons (caar lsts) (apply append (cdar lsts) (cdr lsts))))))
    
    
    > (append (list 1 2 3) (list 4 5 6) (list 'reasonable 'behavior))
    (1 2 3 4 5 6 reasonable behavior)
    

    Which shows a more familiar Scheme style in the absence of mutation, heavy use of recursion
    and no use of sequencing.

    Edit: If you just want to add some elements to a list and not per se join two though:

    (define (extend l . xs)
      (if (null? l) 
          xs
          (cons (car l) (apply extend (cdr l) xs))))
    
    (define (extend! l . xs)
      (if (null? (cdr l))
          (set-cdr! l xs)
          (apply extend! (cdr l) xs)))
    
    (extend '(0 1 2 3) 4 5 6)
    
    (define list1 '(0 1 2 3))
    
    (extend! list1 4 5 6)
    
    list1
    

    Which does what you expect

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

Sidebar

Related Questions

So far i have got the code below which works lovely when trying an
When running the below code a type is never returned, despite there being a
In the below code snippet can i replace char * to const char *
I have the below code in stdafx.h. using namespace std; typedef struct { DWORD
In the below code sample, what does {0:X2} mean? This is from the reflection
In the below code, the ListBox gets filled with the names of the colors
I would like to know how to modify the below code to strip =20
When retrieving objects from an NSMutableArray in cocoa-touch is the below code ok? Should
Okay so I have a scenario similar to the below code, I have a
Code below does not run correctly and throws InvalidOperationExcepiton . public void Foo() {

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.