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

From: Paul Eggert <[email-masked]>
Date: Sun, 26 Apr 2020 18:49:23 -0700

On 4/26/20 5:53 PM, Dmitry Gutov wrote:

> is the behavior of "literal objects" in Emacs
> Lisp undefined when one tries to modify them?

Yes.

>>> Do you have an example of a version of Emacs where this behavior was different?
>>
>> Emacs 26.
> 
> Sorry, I don't have an Emacs 26 at hand. Should 25 suffice?

Yes.

Just tried this in
> IELM:
> ELISP> (setq a '(1 . 2))
> (1 . 2)
> ELISP> (setcdr a 3)
> 3 (#o3, #x3, ?\C-c)
> ELISP> a
> (1 . 3)

Yes, the behavior is undefined in Emacs 25 too. Undefined means that the
behavior you describe is allowed - in this instance you modified the "constant"
and got away with it.

> In Ruby, we also have "constants" and we sometimes laugh about being able to
> change them. And yet, there also you can't do it by accident.

I suppose it depends on what one means by "accident". :-) Perhaps we could agree
that accidents, whatever they are, happen more often in C....

> We better warn against modifying any values that are part of a "literal object"
> anywhere.

That's what the emacs-27 doc does, or at least tries to do.