From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#40671: [DOC] modify literal objects Date: Sun, 19 Apr 2020 20:23:36 -0700 Organization: UCLA Computer Science Department Message-ID: References: <83tv1finob.fsf@gnu.org> <1E9E4C19-37C2-4E24-91B7-8101F9CFBF35@acm.org> <527dc4b5-3176-38b5-f2c1-1483ffc814a1@cs.ucla.edu> <87k12b6sv2.fsf@web.de> <2225099d-16e1-645d-0342-a054da53363f@cs.ucla.edu> <87a7376nv9.fsf@web.de> <99d7a8f9-7732-e1e3-414e-aabbea4433ac@cs.ucla.edu> <87o8rnasfk.fsf@web.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="5290"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 Cc: Mattias =?UTF-8?Q?Engdeg=C3=A5rd?= , 40671@debbugs.gnu.org, ke.vigouroux@laposte.net To: Michael Heerdegen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Apr 20 05:24:15 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jQN2d-0001Gb-04 for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 20 Apr 2020 05:24:15 +0200 Original-Received: from localhost ([::1]:56620 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQN2b-0006fH-Sm for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 19 Apr 2020 23:24:13 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57942 helo=eggs1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jQN2U-0006fB-4c for bug-gnu-emacs@gnu.org; Sun, 19 Apr 2020 23:24:06 -0400 Original-Received: from Debian-exim by eggs1p.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jQN2Q-0003jq-Jb for bug-gnu-emacs@gnu.org; Sun, 19 Apr 2020 23:24:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:34815) by eggs1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jQN2Q-0003jJ-7Y for bug-gnu-emacs@gnu.org; Sun, 19 Apr 2020 23:24:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jQN2Q-00012M-3d for bug-gnu-emacs@gnu.org; Sun, 19 Apr 2020 23:24:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 20 Apr 2020 03:24:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 40671 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 40671-submit@debbugs.gnu.org id=B40671.15873530273964 (code B ref 40671); Mon, 20 Apr 2020 03:24:02 +0000 Original-Received: (at 40671) by debbugs.gnu.org; 20 Apr 2020 03:23:47 +0000 Original-Received: from localhost ([127.0.0.1]:46361 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jQN2A-00011s-R6 for submit@debbugs.gnu.org; Sun, 19 Apr 2020 23:23:47 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:44904) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jQN28-00011c-9W for 40671@debbugs.gnu.org; Sun, 19 Apr 2020 23:23:45 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 46ABA160065; Sun, 19 Apr 2020 20:23:38 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id Z51LtZUjVhd0; Sun, 19 Apr 2020 20:23:37 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 61DB3160079; Sun, 19 Apr 2020 20:23:37 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id sTgkaILQ5iUd; Sun, 19 Apr 2020 20:23:37 -0700 (PDT) Original-Received: from [192.168.1.9] (cpe-23-242-74-103.socal.res.rr.com [23.242.74.103]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 2A634160065; Sun, 19 Apr 2020 20:23:37 -0700 (PDT) In-Reply-To: <87o8rnasfk.fsf@web.de> Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:178695 Archived-At: On 4/19/20 5:53 PM, Michael Heerdegen wrote: > Paul Eggert writes: > >>> (let ((l (list 1 2 3))) >>> `',l) >>> ==> '(1 2 3) >>> If you evaluate this (the return value is a valid expression), >>> `quote' >>> returns a list, but it's not a list literal. >> >> Sure, but one shouldn't be modifying that list. Once you hand a Lisp >> object to 'eval', modifying that object later ought to be a no-no even >> if the interpreter happens to do something non-crashy now. > > But I can modify the list before handing it over to `eval', > e.g. replacing the `1' with `cons'. Yes, that's fine. You can modify the list *before* handing it to eval, but it should be off limits afterwards. That is, the manual doesn't say or imply that the `,l yields a constant, so the result of the `,l is still modifiable. But once you hand the list off to eval, watch out: you shouldn't modify it. Another way to put it is: an object can start off mutable and later become constant when you start using it as part of a program. Come to think of it, perhaps this should be added to the Constants and Mutability section. Something like the following patch, perhaps. diff --git a/doc/lispref/objects.texi b/doc/lispref/objects.texi index abd258eb53..dd7eaf5ae4 100644 --- a/doc/lispref/objects.texi +++ b/doc/lispref/objects.texi @@ -2400,6 +2400,11 @@ Constants and Mutability call @code{(make-string 3 ?a)} yields a mutable string that can be changed via later calls to @code{aset}. + A mutable object can become constant if it is passed to the +@code{eval} function, because you should not modify an object that is +being or might be executed. The reverse does not occur: constant +objects should stay constant. + Trying to modify a constant variable signals an error (@pxref{Constant Variables}). A program should not attempt to modify other types of constants because the > And even when I eval the original list, I get just the same l as before: It's OK that the interpreter does that. But you shouldn't *modify* the original list after handing it off to eval; it might work and it might not. You shouldn't even rely on the interpreter giving you the same l as before, for that matter; that's an implementation detail that is not documented and should not be documented, any more than we should document the fact that (let ((x (cos 1.5))) (eq x (+ x))) returns t in Emacs 27. > We must distinguish between the objects created when a program is > read/compiled, i.e. the objects a program consists of (data and programs > are the same in Lisp, etc.), and the objects that that program actually > handles when it runs. Yes, and the basic idea is that one cannot reliably modify the objects that a program consists of while running the program; it's not safe. (All we need to do is to word this correctly and clearly. :-)