GNU bug report logs - #40671
[DOC] modify literal objects

Previous Next

Package: emacs;

Reported by: Kevin Vigouroux <ke.vigouroux <at> laposte.net>

Date: Thu, 16 Apr 2020 20:40:02 UTC

Severity: normal

Tags: patch

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


Message #108 received at 40671 <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: Drew Adams <drew.adams <at> oracle.com>,
 Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: Mattias EngdegÄrd <mattiase <at> acm.org>,
 40671 <at> debbugs.gnu.org, ke.vigouroux <at> laposte.net
Subject: Re: bug#40671: [DOC] modify literal objects
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.




This bug report was last modified 5 years and 3 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.