bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#40671: [DOC] modify literal objects


From: Paul Eggert
Subject: bug#40671: [DOC] modify literal objects
Date: Wed, 22 Apr 2020 10:21:51 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0

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.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]