From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Pip Cet <pipcet@gmail.com>
Cc: "Basil L. Contovounesios" <contovob@tcd.ie>,
Paul Eggert <eggert@cs.ucla.edu>,
Drew Adams <drew.adams@oracle.com>,
emacs-devel@gnu.org
Subject: Re: master f51f963: Fix some side-effecting uses of make-text-button
Date: Sat, 06 Jun 2020 18:14:29 -0400 [thread overview]
Message-ID: <jwvpnabq2hy.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87pnacxbnk.fsf@gmail.com> (Pip Cet's message of "Sat, 06 Jun 2020 19:00:15 +0000")
> I don't see how literal data is special that way.
In code
(let ((x "foo"))
(cl-assert (eq (aref x 0) ?f))
...)
every programmer I know expects the assertion to be true, always, no
matter what. Yet the assertion will fail if `...` does something like
(aset x 0 ?o).
That's what makes literals special.
This is not unique to Lisp [ tho Lisp experiences this much more because
of the presence of `quote` which makes it possible and common to have arbitrary
literals embedded in the code. ]
IIRC, in C the standard says that modifying a string literal has
undefined behavior.
> If I expect a function to look at a string argument, but it actually
> modifies its argument, that's equally confusing.
I hate mutability, yes. But mutability of literals amounts to
self-modifying code, which is yet a bit more evil.
> If I modify data that's been used in a hash key, that's even more
> confusing. If I modify data in an image spec in a Lisp callback from
> the image backend, Emacs will crash. These cases deserve being
> thought about, too.
We agree, but I'm not sure what it is you're suggesting we should do.
We obviously can't make existing data types unilaterally immutable since
it would break way too much code. Are you suggesting we add new
constructors for "immutable cons", "immutable string", ...?
Or a `set-immutable` function?
> The cost of this isn't negligible; the single bit which I expect will be
> kept for every string, cons cell, or vector isn't that significant, but
> so far what's been proposed would be complicated to implement, explain,
> and use.
I'm not exactly sure what has been suggested, to be honest.
Are you referring to the idea of making literal strings immutable?
I'm not sure what is the implementation plan for such a thing.
It seems at least not completely straightforward.
> It would lead to some people developing a false sense of security and
> others becoming insecure and copying everything needlessly (and
> dangerously, for cyclic objects). And it would effectively prevent any
> competing system of mutability, I fear.
That makes me think there's been a fairly concrete proposal that has
been made and which I missed (since otherwise, it seems unclear how
you'd get to these conclusions). Can someone point me to it?
Stefan
next prev parent reply other threads:[~2020-06-06 22:14 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20200604223056.17078.81265@vcs0.savannah.gnu.org>
[not found] ` <20200604223058.1850020A26@vcs0.savannah.gnu.org>
2020-06-04 22:44 ` master f51f963: Fix some side-effecting uses of make-text-button Stefan Monnier
2020-06-05 0:58 ` Paul Eggert
2020-06-05 9:27 ` Pip Cet
2020-06-05 10:51 ` Basil L. Contovounesios
2020-06-05 12:46 ` Pip Cet
2020-06-05 13:51 ` Basil L. Contovounesios
2020-06-05 14:31 ` Pip Cet
2020-06-05 15:48 ` Basil L. Contovounesios
2020-06-05 18:17 ` Paul Eggert
2020-06-06 8:18 ` Pip Cet
2020-06-06 16:57 ` Drew Adams
2020-06-06 17:57 ` Stefan Monnier
2020-06-06 19:00 ` Pip Cet
2020-06-06 19:49 ` Paul Eggert
2020-06-06 20:23 ` Drew Adams
2020-06-07 9:14 ` Pip Cet
2020-06-06 22:14 ` Stefan Monnier [this message]
2020-06-07 1:40 ` Paul Eggert
2020-06-07 15:24 ` Stefan Monnier
2020-06-07 23:42 ` Paul Eggert
2020-06-07 9:31 ` Pip Cet
2020-06-06 20:19 ` Drew Adams
2020-06-06 17:54 ` Paul Eggert
2020-06-06 19:41 ` Pip Cet
2020-06-06 20:15 ` Paul Eggert
2020-06-07 9:21 ` Pip Cet
2020-06-07 23:37 ` Paul Eggert
2020-06-06 20:11 ` Drew Adams
2020-06-06 22:16 ` Stefan Monnier
2020-06-06 23:27 ` Drew Adams
2020-06-05 13:02 ` Stefan Monnier
2020-06-05 13:50 ` Basil L. Contovounesios
2020-06-06 19:09 ` Paul Eggert
2020-06-06 20:19 ` Drew Adams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvpnabq2hy.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=contovob@tcd.ie \
--cc=drew.adams@oracle.com \
--cc=eggert@cs.ucla.edu \
--cc=emacs-devel@gnu.org \
--cc=pipcet@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).