help-gnu-emacs
[Top][All Lists]
Advanced

[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: Mon, 21 Jun 2021 00:54:58 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Jean Louis wrote:

>> (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) <-- the tail has changed
>> (setcar list-head 1.5)
>> whole-list ; <-- but here, the head is still unaffected, (1 2 3.5 4)
>> (setcar whole-list 1.33) ; well, of course that will work...
>> whole-list ; (1.33 2 3.5 4)
>> list-head ; still (1.5)
>
> (setq list-head '(1)) ⇒ (1)
> (setq list-tail '(2 3 4)) ⇒ (2 3 4)
> (setq whole-list (append list-head (copy-sequence list-tail))) ⇒ (1 2 3 4)
> (setcdr list-tail '(3.5 4)) ⇒ (3.5 4) ; (3.5 4)
> It did not change now:
> whole-list ⇒ (1 2 3 4) ; (1 2 3.5 4) <-- the tail has changed

But here it did again, despite `copy-sequence'!

(progn
  (setq list-head '(1))
  (setq list-tail '(2 3 4))
  (setq list-tail-2 (copy-sequence list-tail))
  (setq whole-list (append list-head list-tail-2))
  (setcdr list-tail-2 '(3.5 4))
  whole-list
) ; (1 2 3.5 4)

Oh, no!

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

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