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))
(setq list2 '(a b c))
(setcar list1 'A)
But if I evaluate
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.
...Because we intend to use
setcarto change the list, this
setqshould 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 the
listfunction, as follows:
setq animals (list 'antelope 'giraffe 'lion 'tiger))