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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:46:12+00:00 2026-05-26T11:46:12+00:00

Using set! I want to be able to modify a local state list variable

  • 0

Using set! I want to be able to modify a local state list variable lst, but only a part of it

For example, I want to insert values inside an inner list:

((1 2) (4 5))

becomes

((1 2 3) (4 5))

I want to be able to do something like set! (car lst) (append (car lst) 3)

But that seems to only modify the temporary variable generated by (car lst).

The only way I can think of is to create a new list with the new desired values and set lst to be the new list, but that seems wasteful and unnecessary. Is there a better way to do it?

  • 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-26T11:46:13+00:00Added an answer on May 26, 2026 at 11:46 am

    try this:

    (define lst (list (list 1 2) (list 4 5)))
    lst
    > ((1 2) (4 5))
    (set-cdr! (cdar lst) (list 3))
    lst
    > ((1 2 3) (4 5))
    

    when modifying cons/lists you should use set-cdr! and set-car!

    EDIT: for racket

    use mutable list:

    (require racket/mpair)
    (define lst (mlist (mlist 1 2) (mlist 4 5)))
    lst
    > (mcons (mcons 1 (mcons 2 '())) (mcons (mcons 4 (mcons 5 '())) '()))
    (set-mcdr! (mcdr (mcar lst)) (list 3))
    > (mcons (mcons 1 (mcons 2 #<promise:temp2>)) (mcons (mcons 4 (mcons 5 '())) '()))
    lst
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a complete example. I want to forbid using A::set from objects casted
I want to be able to get and set the date using my own
I'm using awesome_nested_set for my central website structure. I want to be able to
I am using a set because, i want to use the quick look up
I just want to set a crontab using that I want to make a
I want to set the background color of a label using HSV instead of
I am using wxPython's HyperTreeList and I want to set the column width exactly
I'm configuring a web site using PowerShell and I want to set the default
in my site i want to set default page to open, using this script
Using WPF, I have a TreeView control that I want to set its ItemTemplate

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.