Subject: Re: bug#40671: [DOC] modify literal objects

From: Paul Eggert <[email-masked]>
Date: Fri, 24 Apr 2020 19:22:22 -0700

On 4/22/20 5:49 PM, Michael Heerdegen wrote:

> +  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.
> 
> `eval' is used quite rarely.  Can what you describe happen under other
> circumstances, or does it only happen to `eval'?  E.g. what about this
> case for example:
> 
>   (let ((l (list 1 2 3)))
>     (funcall (lambda () l)))
> 
> Has the list become a constant?

No, because the list is not part of the expression that is being evaluated.
However, something like this could cause trouble:

(let ((l (list 'lambda '(x) '(setcdr l x))))
  (eval (list l l)))

because it modifies the list l while it is evaluating it. (As it happens, this
code behaves differently in Emacs 26 than it does in Emacs 27 - that's what you
can get with undefined behavior....)

> Maybe I misread "might be executed" as
> "might be executed in the future" and you actually meant something like
> "might (currently) be executed (as part of the expression the
> interpreter currently executes).
> 
> BTW, speaking about Lisp the term "evaluate" is probably preferable to
> "execute" I think.

Both good points. The word "executed" is already gone from the manual, and I
installed the attached patch to try to address the other point.
>From 49bc5a63f7d6178f136d9e28bcacda3acfc375d3 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Fri, 24 Apr 2020 19:19:31 -0700
Subject: [PATCH] Tweak mutability doc a bit more

Inspired by a comment from Michael Heerdegen (Bug#40671#114).
* doc/lispref/objects.texi (Constants and Mutability): Tweak further.
---
 doc/lispref/objects.texi | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/doc/lispref/objects.texi b/doc/lispref/objects.texi
index 1eda94ab63..b4e9ff4411 100644
--- a/doc/lispref/objects.texi
+++ b/doc/lispref/objects.texi
@@ -2401,8 +2401,8 @@ 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 a program should not modify an object
+  A mutable object can become constant if it is part of an expression
+that is evaluated, because a program should not modify an object
 that is being evaluated.  The reverse does not occur: constant objects
 should stay constant.
 
-- 
2.17.1