[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: Kevin Wortman
Subject: Re: [Chicken-users] Replace an element in a list
Date: Mon, 15 Dec 2014 11:18:25 -0800

Yes, it would be OK to use split-at to break a list into two pieces then reassemble it. That approach is relatively expensive though, since it's O(n) and involves re-allocating potentially many list nodes, which is why folks have suggested alternative approaches.

Does it happen to be the case that you're trying to initialize a list one element at a time? I might be reading too much into this, but I get the sense you're trying to do something like

for (i = 0; i < n; i++)
  new_list[i] = <_expression_>;

While that is commonplace and idiomatic in imperative languages, it's not in Scheme. Instead it'd be more Schemely to use something like map or list-tabulate from SRFI 1.

Kevin Wortman

On Sat, Dec 13, 2014 at 11:34 PM, Bahman Movaqar <address@hidden> wrote:
Thanks Daniel and John.

I found "split-at" while reading the docs last night. Along with
"let-values" it seems like a natural answer to my questions. What do you
folks think?

Bahman Movaqar - -
PGP Key ID: 0x6AB5BD68 (

On 12/14/2014 03:29 AM, Bahman Movaqar wrote:
> 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?

Chicken-users mailing list

reply via email to

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