Subject: Re: bug#75170: add-to-alist: new function

From: Stefan Kangas <[email-masked]>
Date: Mon, 20 Jan 2025 14:41:28 -0600

Roland Winkler <[email-masked]> writes:

> On Mon, Jan 20 2025, Robert Pluim wrote:
>> Iʼm not sure what this would offer over
>>
>>     (setf (alist-get key alist) value)
>>
>> which will add a key->value mapping if it doesnʼt exist, and replace
>> it if it does. I also donʼt see a real use for retaining the existing
>> mapping: `alist-get' will return the first one anyway.
>
> By now, this approach has been proposed in this thread a few times.
> The question is: this uses the concept of generalized variables.
> Is this a concept we recommend to users for their init files?
> To the best of my knowledge, previously this has not been the case.
> I am tempted to argue that in our recommendations what users should
> do in their init files, we should stick to strategies that are as
> simple and transparent as possible, and the above does not match
> that criterion.  A collection of functions we recommend to users for
> their init files might be a good thing.  add-to-list already serves
> that specific purpose, and add-to-alist could be another one.

I certainly appreciate the arguments against adding more redundancy to
ELisp, but I think the point still stands that Emacs should be easy to
customize.  Generalized variables don't do that job in my book.

Michael Heerdegen pointed out that `map-put!` could though, given:

    (setq foo '((clown . foot) (thunder . clap)))

We get:

    (map-put! foo 'clown 'hand)

Which I compare to:

    (add-to-alist foo '((clown . hand)))

Is that a workable alternative?  We lose the symmetry with `add-to-list`
of course, but there are fewer parentheses and dots to get wrong, and
all we need do is promote it.  Which may or may not be easy.