I'm reading An Introduction to Programming in Emacs Lisp by Robert J. Chassell.
When the book is introducing setcar
, it points out that when we use this function to a list, the list should be initialized in this way:
(setq list1 (list 'a 'b 'c))
instead of
(setq list2 '(a b c))
And then
(setcar list1 'A)
But if I evaluate list1
and list2
, Emacs gives me the same list (a b c)
.
I don't see any difference here. As a matter of fact, (setcar list2 'A)
is also evaluated successfully.
Page 76
...Because we intend to usesetcar
to change the list, thissetq
should not use the quoted form'(antolope giraffe lion tiger)
, as that would yield a list that is part of the program and bad things could happen if we tried to change part of the program while running it.
Generally speaking an Emacs Lisp program's components should be constant (or unchanged) while the program is running. So we instead construct an animal list by using thelist
function, as follows:setq animals (list 'antelope 'giraffe 'lion 'tiger))
(info "(elisp) Mutability")
.