Subject: bug#42147: 28.0.50; pure vs side-effect-free, missing optimizations?

From: Mattias Engdegård <[email-masked]>
Date: Thu, 9 Jul 2020 12:20:34 +0200

9 juli 2020 kl. 00.19 skrev Andrea Corallo <[email-masked]>:

> Or is it maybe that the only way to certainly have a mutable string is
> with `copy-sequence' or `make-string'?

Yes; since the need for a mutable value is very unlikely, creating a fresh copy every time just in case would be a big waste of resources. Otherwise, we could only 'optimise'

 (concat "abc" "def")

to

 (copy-sequence "abcdef")

which would be a very modest improvement, for very little gain.

The two functions you mentioned are indeed guaranteed to return fresh, mutable strings and thus cannot be marked 'pure'.

String mutation is something of a special case: it is rare, yet its mere possibility incurs costs even for code that doesn't use it. Better try to keep that cost to a minimum.