Jean-Christophe Helary
2018-12-02 10:53:35 UTC
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
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