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

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

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


From: Jean-Christophe Helary
Subject: Re: using setq to create lists based on other lists...
Date: Sun, 2 Dec 2018 22:28:39 +0900


> On Dec 2, 2018, at 22:08, Stephen Berman <stephen.berman@gmx.net> wrote:
>> 
>> That's not clear at all from the paragraph you quote. Because for all
>> practical purposes, when I evaluate list0 I get (1 2) and not "a pointer to 
>> an
>> object that is the list (1 2)".
>> 
>> In fact, I just found the explanation, it is in the Introduction to Emacs 
>> Lisp
>> and it says:
>> 
>>> When a variable is set to a list with a function such as setq, it stores the
>>> address of the first box in the variable.
>> 
>> So, setq has a specific behavior when it applies to lists: it evaluates the
>> form as a pointer to an object and not as a value.
> 
> I don't think setq is behaving any different with lists than with other
> Lisp objects.  Lists are defined this way in Lisp, cf. (info "(elisp)
> Cons Cell Type"):

Yes, but a list does not generally evaluate to a pointer to the first cell of 
its cons. Which is the case when setq is used. Which is the reason why the 
Introduction insists on that aspect of setq, because before that, all the setq 
examples assigned "straight" values to variables.

For ex. The first sentences of "Global Variables" in the Reference are like 
this:

> You specify a value for a symbol with setq. For example, (setq x '(a b))
> gives the variable x the value (a b).

They don't say:

(setq x '(a b)) stores the address of the first (cons) cell in the variable. 

Which it does, and which is confusing if you expect x to hold '(a b), like I 
was today.

So I think it would be nice to add a few lines here and there to clarify that 
behavior.


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





reply via email to

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