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: Michael Heerdegen
Subject: Re: using setq to create lists based on other lists...
Date: Sun, 02 Dec 2018 15:40:01 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Jean-Christophe Helary <brandelune@gmail.com> writes:

> > 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.

When one is saying that lists are referenced by pointers this is mainly
to help people coming from other programming languages to understand
that multiple variables can be bound to the same object.  It's probably
better to say that multiple variables can be bound to the same value (or
object).

Apart from that, note that a list is identical to its first 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.

There is nothing special with setq here, really.  Whenever you refer to
the same Lisp object in different places in your code in whatever way,
you see the same object modified in all places at the same time when you
modify it.  Variables bound to the same value (via setq or in any other
way) is only one case.  In Lisp it's always like that, as long as you
look at the same value.

It is also not special to lists: you get the same for all objects that
can be modified, like any conses and trees, strings, arrays, keymaps
(which are actually lists), defstructs, eieio objects, vectors,
bool-vectors, ...

Michael.




reply via email to

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