[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [External] : Re: Appending lists
From: |
Emanuel Berg |
Subject: |
Re: [External] : Re: Appending lists |
Date: |
Sun, 20 Jun 2021 22:42:00 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Jean Louis wrote:
> But then I can use the previously defined variables to
> define a new one:
>
> (setq appended (append list-a list-b)) ⇒ (1 2 3 a b c)
>
> and nothing changed in those:
>
> list-a ⇒ (1 2 3)
> list-b ⇒ (a b c)
Actually `append' can also be trouble because the last list
isn't copied, the new list just has a cdr somewhere to it -
yes, to the actual list.
Try this:
(setq list-head '(1)) ; (1)
(setq list-tail '(2 3 4)) ; (2 3 4)
(setq whole-list (append list-head list-tail)) ; (1 2 3 4)
(setcdr list-tail '(3.5 4)) ; (3.5 4)
whole-list ; (1 2 3.5 4)
See that "whole-list" changed even tho we did it with `setq',
append, and didn't mention it...
I don't know why append does this, either to speed things up
or it has something to do with the car/cdr dynamic, maybe it
is considered safe enough to move the car out of action with
an actual copy ...
--
underground experts united
https://dataswamp.org/~incal
- Re: Appending lists, (continued)
- Re: Appending lists, Emanuel Berg, 2021/06/18
- Re: Appending lists, tomas, 2021/06/19
- Re: Appending lists, Emanuel Berg, 2021/06/19
- RE: [External] : Re: Appending lists, Drew Adams, 2021/06/19
- Re: [External] : Re: Appending lists, Emanuel Berg, 2021/06/20
- Re: [External] : Re: Appending lists, Emanuel Berg, 2021/06/20
- Re: [External] : Re: Appending lists, Jean Louis, 2021/06/20
- Re: [External] : Re: Appending lists, Emanuel Berg, 2021/06/20
- Re: [External] : Re: Appending lists, Jean Louis, 2021/06/20
- Re: [External] : Re: Appending lists, Emanuel Berg, 2021/06/20
- Re: [External] : Re: Appending lists,
Emanuel Berg <=
- Re: [External] : Re: Appending lists, Emanuel Berg, 2021/06/20
- Re: [External] : Re: Appending lists, Jean Louis, 2021/06/20
- Re: [External] : Re: Appending lists, Emanuel Berg, 2021/06/20
- Re: [External] : Re: Appending lists, Jean Louis, 2021/06/20
- Re: [External] : Re: Appending lists, Emanuel Berg, 2021/06/20
- Re: [External] : Re: Appending lists, Jean Louis, 2021/06/20
- Re: [External] : Re: Appending lists, Stefan Monnier, 2021/06/20
- Re: [External] : Re: Appending lists, Emanuel Berg, 2021/06/20
- Re: [External] : Re: Appending lists, Emanuel Berg, 2021/06/20