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

From: Stefan Kangas <[email-masked]>
Date: Mon, 20 Jan 2025 15:40:48 -0600

Roland Winkler <[email-masked]> writes:

> On Mon, Jan 20 2025, Stefan Kangas wrote:
>> Michael Heerdegen pointed out that `map-put!` could though, given:
>>
>>     (setq foo '((clown . foot) (thunder . clap)))
>>
>> We get:
>>
>>     (map-put! foo 'clown 'hand)
>
> How does map-put! test for the presence of a key (by default)?
> This is not documented in the docstring.

It's not documented, but my testing shows that after the above recipe,
foo has this value:

    ((clown . hand) (thunder . clap))

>> Which I compare to:
>>
>>     (add-to-alist foo '((clown . hand)))
>
> I think this should read
>
>       (add-to-alist 'foo '(clown . hand))
>
> which has fewer parentheses, but foo must be quoted, like with add-to-list.

You're right, thanks for correcting that.  So less ugly than what I
wrote, and close to what an alist looks like anyways.

I'm curious to hear more opinions about `map-put!`.  I'm also copying in
Stefan Monnier, who added that function (or at least named it).

>> 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.