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 16:00:09 +0100 Message-ID: <87r2f02cue.fsf@rub.de> References: <874lbw4059.fsf@gmx.net> <87zhto2i0d.fsf@gmx.net> <6512D5B6-B3BE-4B02-81E0-B73F4BED9FCE@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1543762726 15130 195.159.176.226 (2 Dec 2018 14:58:46 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 2 Dec 2018 14:58:46 +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 15:58:42 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 1gTTCj-0003lV-9r for geh-help-gnu-emacs@m.gmane.org; Sun, 02 Dec 2018 15:58:41 +0100 Original-Received: from localhost ([::1]:44838 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gTTEp-00026J-T6 for geh-help-gnu-emacs@m.gmane.org; Sun, 02 Dec 2018 10:00:51 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57027) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gTTEH-000269-RS for help-gnu-emacs@gnu.org; Sun, 02 Dec 2018 10:00:18 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gTTEC-0000p7-Im for help-gnu-emacs@gnu.org; Sun, 02 Dec 2018 10:00:17 -0500 Original-Received: from mout.gmx.net ([212.227.17.20]:36083) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gTTEC-0000oN-9h for help-gnu-emacs@gnu.org; Sun, 02 Dec 2018 10:00:12 -0500 Original-Received: from rosalinde ([188.109.205.60]) by mail.gmx.com (mrgmx102 [212.227.17.168]) with ESMTPSA (Nemesis) id 0M9eHT-1geigv16fn-00D0pY; Sun, 02 Dec 2018 16:00:10 +0100 In-Reply-To: <6512D5B6-B3BE-4B02-81E0-B73F4BED9FCE@gmail.com> (Jean-Christophe Helary's message of "Sun, 2 Dec 2018 22:28:39 +0900") X-Provags-ID: V03:K1:BHCz89umwjqUM8c9EuRTDOhfW1bs18HNNRize3QlsmU1VgczRuI 1O/llJdkHyQlpE8HvHQgMGuQ/oS/xOff9UyxA1Yez45oU8/paD9kOyPMW0D724Z9SbsvYsr Hh3N7MbCPtUXv+0ckVIvKXtNwA58ymGR1op2wEebj8Rj8V3Ou2DBwKmcEDctSNU1CqRWm1h zw75jzHzfTtZM6CqoBpgQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:RUXKP4aItOg=:sXMfx9ocdYZGe89e09nR21 Xjw1TSgI5ip9bMLeg11kP+RuL0YevZeDTAo/oLxFTMGYEoTyP3/EZOZ7L4H8bQ7LaQ4GYtwNC iCV8L0jDfIe1PuREBz5oH3bCFzdxGTWHx1XaudxuJBCN1nplX+xYr7w6ZNZcCrGvYnrw6SdnJ WXCOSbdtokzAs4zs0LTsNLPrTFQZKRzXQFLn0kLKhWPmEjBCpDAu9MhDHNjWJf3Bap68oIUEd FMCnZbQgrh3nKpNbgMC+qHSTmAxH/yemBJyCJgYVSKOqM51JheWwMcFQWmGZkjLH/IMXGUdif rw5+78mmmF0xpFi/uH4DW2JHEKNjqVu0NGJnPggO1LWIXv2c6Jyh2+QplJ22E3ypIwstdF3qO bPCqDURDpe5HJhCkOXtOS7VkD/RGyNUMOzL6Hn8yjPTnJnKBPdh4XJQZtVN4n/Ir2LaJlA0PZ rUAFtJ4VBGFRqtz9AR/LcBKh08Cvbx7edo7l8YXtU0KH8YfQqrbSdpACrRSU6MOpewF5D7Cbc 2h+5gtFhZc8UyuYXFE2QBwwDWCbkg4SEIo2aG7M0m9a5IIK6t8PwHdYsXJ1BAvKzIGnEaodEE Ss8/he3iKeiptzN2LXyiniMVeStdNWHg5oVxceWfqooo3BOYKuY3Hr4dY0JL2Nl/+XeSuxgQg VURZZe/TfkWF9BHhQKTFf+N7n/bJcMB7z2NOGGSWZ7cjhNLjQUCxoE7MFvNd+nD/D/R+II4cl Gvqfo+vhoM2DVKU3uzEe8SVieKyMTJWuBzsCBp31gJHO5LoJ/S1QsB5tFiVBqtDtaPMzS3sZ X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.17.20 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:118827 Archived-At: On Sun, 2 Dec 2018 22:28:39 +0900 Jean-Christophe Helary wrote: >> On Dec 2, 2018, at 22:08, Stephen Berman wrote: [...] >> >> 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. I think your confusion may be due to not distinguishing the value assigned by setq, which is a particular object, and the form of the value, which may look the same but nevertheless be a different object. Look again at your original example: (setq list0 '(1 2)) (setq list1 list0) I pointed out that the second setq sets the value of `list1' to the value of `list0', so they refer to the same object: (eq list1 list0) => t But if you now do this: (setq list1 '(1 2)) you have set the value of `list1' to a new list, which happens to have the same structure as the value of `list0' but is not the same object: (eq list1 list0) => nil And now (setcar list0 3) turns the value of `list0' into (3 2) but the value of `list1' is still (1 2). You see the same behavior e.g. with strings (which are implemented in C as arrays, i.e. a variable whose value is a string points to the address of the first element of the array holding the characters of the string): (setq str0 "bla") (setq str1 str0) (eq str1 str0) => t (setq str1 "bla") (eq str1 str0) => nil So there is no special behavior of setq, but differences due to the objects themselves. Steve Berman