[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Replace an element in a list

From: John Cowan
Subject: Re: [Chicken-users] Replace an element in a list
Date: Sat, 13 Dec 2014 21:44:09 -0500
User-agent: Mutt/1.5.20 (2009-06-14)

Bahman Movaqar scripsit:

> What is the idiomatic way of replacing the nth element in a list
> *without* mutating the list? Is the combination of "take" and
> "take-right" the right way to do it?

Yes, that's how I'd do it.

Daniel Leslie scripsit:

> There are setters for car and cdr, so let's say you're at a position where
> you want to replace the head of a list, you can then just do:
> (set! (car some-list) some-value)

That's how you do it when you *do* want to mutate the list, or you can
use list-set! if you have it (as R7RS does).

John Cowan        address@hidden
You annoy me, Rattray!  You disgust me! You irritate me unspeakably!
Thank Heaven, I am a man of equable temper, or I should scarcely be able
to contain myself before your mocking visage.  --Stalky imitating Macrea

reply via email to

[Prev in Thread] Current Thread [Next in Thread]