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

From: Paul Eggert <[email-masked]>
Date: Wed, 22 Apr 2020 10:21:51 -0700

On 4/19/20 10:54 PM, Drew Adams wrote:

> A mutable object cannot be changed to a constant

Sure they can. This idea is common in other languages, e.g., see Object.freeze 
method in JavaScript. There's no reason Emacs Lisp can't use the idea.

>> +A mutable object can become constant if it is passed to the
>> +@code{eval} function,
> 
> How so?  What's an example?

(let ((x (make-string 1 ?a)))
   (eval `(progn
	   (defun foo ()
	     (let ((a ,x))
	       (aset x 0 ?b)
	       (list a "a" (equal a "a"))))
	   (byte-compile 'foo)
	   (foo))))

This code is not well-formed because it modifies the string x after passing it 
to eval (such strings should be constant). As a result, the behavior of the 
program is unpredictable. On master it currently yields ("b" "b" t) but there's 
no guarantee of this.