[Warning : these are noob questions.]
I'm a beginner in Emacs Lisp and I would like to be sure that I understand well what I'm really doing when I set a value to a variable with
Here is a piece of code:
(setq x '(1 2 3 4)) ; define x (setq y x) ; define y (setcar y 9) ; modify CAR of y y ; -> (9 2 3 4): y has changed (ok) x ; -> (9 2 3 4): but x has changed too!
It seems that when you define a symbol and give it the value of another symbol, this basically means that the two symbols become the same object?
(eq x y) ; -> t
(I expected that the instruction
(setq y x)would make an "independant copy" of
x, as it would be the case if you do
y <- xin R language for example. Or, more formally, I thought this instruction would only fill the "value cell" of
(symbol-value 'x), but without "binding" those two objects together.)
This is really a matter of pointers, if I understand well.
(setq y x)creates a new symbol which is basically bound to the same address as
xwhich points towards a given value, and so if you modify
y, you will also modify
xbecause both of them point towards the same address "by transitivity"?)
Robert Chassell's book says that "when a Lisp variable is set to a value, it is provided with the address of the list to which the variable refers", but I cannot figure out what this means formally (where is this address stored?). A Lisp symbol is made of 4 components (name, value, function, properties). So, when I do
(setq y x), the "value cell" of
yis really an address / a pointer towards