emacs-devel
[Top][All Lists]
Advanced

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

Re: `aset` on strings, changing the size in bytes


From: Noam Postavsky
Subject: Re: `aset` on strings, changing the size in bytes
Date: Sun, 9 Sep 2018 12:27:21 -0400

On 9 September 2018 at 11:17, Eli Zaretskii <address@hidden> wrote:

> I meant to make aset cons a new string when it turns out the original
> one's data is too small to include the new contents.
>
>> the semantics of aset is to modify the original string, changing
>> that would surely break code that worked for decades.
>
> But if we are going to tell people aset won't work in those cases,
> that code will be broken as well, no?

Ah, I think I see the disconnect. You mean aset should return a new
string only in the case where the string needs to be resized (rather
than signalling an error), but otherwise continue to modify the string
in-place and return NEWELT as normal.

A conditional return value like that seems too awkward to be useful,
IMO. Instead of

(setq s (sset s idx newchar)) ; as in [1]

You would need:

(let ((new-s (aset s idx newchar)))
  (when (stringp new-s)
    (setq s new-s)))

In practice, I suspect people wouldn't bother a lot of the time, so in
the rare case where a string is resized there will just be confusingly
wrong answer instead of a clear error.

[1]: https://lists.gnu.org/archive/html/emacs-devel/2018-09/msg00387.html



reply via email to

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