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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:41:50+00:00 2026-05-25T09:41:50+00:00

(require racket/mpair) (define (bld-mlst . args) (list->mlist args)) (define mlst-my (bld-mlst)) mlst-my (mappend! mlst-my

  • 0
(require racket/mpair)

(define (bld-mlst . args)
  (list->mlist args))

(define mlst-my (bld-mlst))
mlst-my

(mappend! mlst-my (list->mlist (list 100)))
mlst-my

(define mlst-my2 (bld-mlst 2))

(mappend! mlst-my2 (list->mlist (list 100)))
mlst-my2

it will print out:

(mcons 100 '())
'()
(mcons 2 (mcons 100 '()))
(mcons 2 (mcons 100 '()))

The first and third line is just the return value of the mappend! Note the second line and fourth line! We can see that the second line is '(), which means that mappend! does not change the mlst-my! While when the mlst-my2 is not empty, the mappend! works fine.
Question:
Then How to make the mappend! to still side effect the mlist when the mlist is empty?

  • 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-25T09:41:51+00:00Added an answer on May 25, 2026 at 9:41 am

    You can’t! The empty list is a singleton, immutable object. It has no slots (car or cdr) that you can change. But you can do this:

    (set! mlst-my (mappend! mlst-my (list->mlist (list 100))))
    

    That is, you set! your variable to mappend!‘s return value.


    To understand all that, understand how singly linked lists work. It comprises cons cells (or dotted pairs), which each have two slots (traditionally named car and cdr). The car slot points to the value, and the cdr points to the next cons/pair.

    So, a list like (1 2 3) has three conses:

    #0=(1 . #1#)
    #1=(2 . #2#)
    #2=(3 . ())
    

    The way append! works is to find the last cons (the one whose cdr is pointing to ()), and change its cdr to point to the list you’re appending.

    If your list is empty, though, it has no conses, and therefore it has nothing to change. Empty lists are always immutable.

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

Sidebar

Related Questions

require 'open-uri' print Enter a URL add = gets open(#{add}) do |f| j =
require.config({ paths: { jquery: 'libs/jquery', underscore: 'libs/underscore', } }); define([ 'jquery', 'underscore', ], function($,_){
require 'pp' p *1..10 This prints out 1-10. Why is this so concise? And
require_once'modules/logger.php'; $Logger = new Logger(); require_once 'templates/list.php'; $Templates = new templatesList(); require_once 'widgets/list.php'; $Widgets
require 'sinatra/base' class Foo < Sinatra::Base get('/foo') { 'foo' } end class Bar <
Require a huge help here, since this is affecting our production instance. One of
require_once('/recaptcha/recaptchalib.php'); was in the correct place but the error says: Warning: require_once() [function.require-once]: open_basedir
I require a tree / directed acyclic graph implementation something like this: public class
I require a star rating control (which allows partial rating like 4.5) for my
I require a SQL script to validate a VARCHAR field in a table in

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.