From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.help Subject: Re: using setq to create lists based on other lists... Date: Sun, 02 Dec 2018 14:08:34 +0100 Message-ID: <87zhto2i0d.fsf@gmx.net> References: <874lbw4059.fsf@gmx.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1543756037 2236 195.159.176.226 (2 Dec 2018 13:07:17 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 2 Dec 2018 13:07:17 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: help-gnu-emacs To: Jean-Christophe Helary Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Dec 02 14:07:13 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gTRSl-0000Lu-IQ for geh-help-gnu-emacs@m.gmane.org; Sun, 02 Dec 2018 14:07:07 +0100 Original-Received: from localhost ([::1]:44562 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gTRUs-0002wS-02 for geh-help-gnu-emacs@m.gmane.org; Sun, 02 Dec 2018 08:09:18 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36219) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gTRUH-0002vO-F2 for help-gnu-emacs@gnu.org; Sun, 02 Dec 2018 08:08:42 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gTRUD-0007ZY-JK for help-gnu-emacs@gnu.org; Sun, 02 Dec 2018 08:08:41 -0500 Original-Received: from mout.gmx.net ([212.227.15.15]:52267) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gTRUD-0007ZH-Ax for help-gnu-emacs@gnu.org; Sun, 02 Dec 2018 08:08:37 -0500 Original-Received: from rosalinde ([188.109.205.60]) by mail.gmx.com (mrgmx001 [212.227.17.190]) with ESMTPSA (Nemesis) id 0LpbJm-1h7RSv1UD0-00fU8M; Sun, 02 Dec 2018 14:08:35 +0100 In-Reply-To: (Jean-Christophe Helary's message of "Sun, 2 Dec 2018 21:22:54 +0900") X-Provags-ID: V03:K1:qZvX13Vh5uQ8ysn4hQz5fG8ftOyaA9MeAEsj8Ux2FrKD4bw3j2U klFqYJxkgdjJbJDQsBLQ9vAkAbuKBGrpAoFz+5/86UDoPrA1sISuXgHnhL+kpAhjZbFVgIv Fblznl6VweOt4EmxQDLbxvbdG99ZdAzlbkmMPEln10bW8BSD35cjByDKo+EiN8xMt/isKX4 2SH7k9E5TqIZcbOaVlGWA== X-UI-Out-Filterresults: notjunk:1;V03:K0:L5iYfjw0drw=:2ZTdff5Ma3TsuIerUPsHW9 ZhQieXNeViZ0mAVW/rzltqkylBN9z9OSp4K2XAdzWTkQn+MVFunMSJMqDviS99PmEo+iqE5wv SLBb/uz6Umi0aUH/8qCh3DoJv8XDuVWn5oJaMyWPSdkozZ75J3wJFFrtClfrOW/S9n3wuGm+d hGI6wvrH2BrO3q8Ec7l0n2yF5Zjw5qeyNQcR/mis093iKeN96D5xra077nf1gAAp19sACyp2H wYR770HghmUuBLVoJ4bCVnO4+nwuH7Ec+SHPdh+e2guo0zlsVMXl6LTxidnCcjqcI8inR9fKr 8JJZpe1y0HNWw2+/CfkSbutq7aSFVXr/zy4CmwIldSv+N7viZa0innesSrJ0aQZpUeO+0a/pD 8vXiuJBG1A8cdK1h9XuBWZRAroYW1C3AIhXoLgU6NR21emqIeTSt5D4V4zvVPZIHLH++kxIPr VJGZi4eCxhdqw0jF5SnruYziIsG3ihjpeWvE3gRJL5v92+Gs7h8wi0XeE5Hcbc5aKzbm6YjgF XicMM5D8vMvBT+eZbbjvdZt8GuP9mN+Vol22zzXMt+r4BWGJAzYTm5B2FWbZXIBH77HUZjc6B cqcEQldj+dxDBwUSFTytnAJn5haVqJSEVm0oFfKpVuXt7PJ2bGCtWsfvEXTyELegXB7T8phNG sWcUAYrmoDCJdCDJX1tiXKLvvw9sUPeXJAUdSjgesPJuwH/hXbvQDxWETilMdTGIlSeT2H+uy BXrCQY/WXqO2k3+OrvEk17xEdzpdIvWP6SxlWx0sv/54shD3BZ1uc2/vMjx+KDVVGZyxCoL8 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.15.15 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:118824 Archived-At: On Sun, 2 Dec 2018 21:22:54 +0900 Jean-Christophe Helary wrote: > Stephen, thank you for the additional explanations. > >> On Dec 2, 2018, at 20:51, Stephen Berman wrote: > >>>> I don't suppose that's a bug, but really it ought the be very clearly= =20 >>>> documented in the reference. Also, I'd like to know why that's happeni= ng. >>=20 >> To expand of this, since Jean-Christophe didn't find an explanation of >> this behavior of setq in the Lisp reference, but it is in fact >> documented: > > Well, yes and no. > >> Special Form: setq [symbol form]... >> This special form is the most common method of changing a >> variable=E2=80=99s value. Each SYMBOL is given a new value, which i= s the >> result of evaluating the corresponding FORM. The current binding >> of the symbol is changed. >>=20 >> In the above case, the symbol `list1' is given the result of evaluating >> `list0', which is the list `'(1 2)'. So now both `list0' and `list1' >> refer to this list, > > 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 t= he > 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"): A =E2=80=9Clist=E2=80=9D is a series of cons cells, linked together so t= hat the CDR slot of each cons cell holds either the next cons cell or the empty list. [...] A note to C programmers: a Lisp list thus works as a =E2=80=9Clinked l= ist=E2=80=9D built up of cons cells. Because pointers in Lisp are implicit, we do not distinguish between a cons cell slot holding a value versus pointing to the value. See also the diagrams and explanations in (info "(elisp) Box Diagrams") and in the discussion of `append' in (info "(elisp) Building Lists"). Steve Berman