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

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

using setq to create lists based on other lists...


From: Jean-Christophe Helary
Subject: using setq to create lists based on other lists...
Date: Sun, 2 Dec 2018 19:53:35 +0900

I spend most of the day investigating why creating a list with setq was not 
"working".

For ex:
(setq list0 '(1 2))
(setq list1 list0)

If you do

(setcar list0 0)

then for some reason (for which I could not find an explanation in the elisp 
reference) the car of list1 also changes, and vice-versa.

Which is totally unexpected since when you do:

(setq list0 0)

list1 does not become 0

I don't suppose that's a bug, but really it ought the be very clearly 
documented in the reference. Also, I'd like to know why that's happening.

So, to avoid that behavior, I had to resort to using copy-tree:

(setq list1 (copy-tree list0))

Which is really not the first thing I would have thought about.

There are probably better ways to create lists based on other lists without 
"linking" the two, so I'd like some information about that.

Thanks in advance.



Jean-Christophe Helary
-----------------------------------------------
http://mac4translators.blogspot.com @brandelune





reply via email to

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