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.

Regards,
Kevin Wortman


On Sat, Dec 13, 2014 at 11:34 PM, Bahman Movaqar <[email protected]> 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
>
> http://BahmanM.com - https://twitter.com/bahman__m
> https://github.com/bahmanm - https://gist.github.com/bahmanm
> PGP Key ID: 0x6AB5BD68 (keyserver2.pgp.com)
>
> 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
> [email protected]
> https://lists.nongnu.org/mailman/listinfo/chicken-users
>
>
_______________________________________________
Chicken-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/chicken-users

Reply via email to