GNU bug report logs -
#75170
add-to-alist: new function
Previous Next
Full log
View this message in rfc822 format
Roland Winkler <winkler <at> gnu.org> 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.
This bug report was last modified 142 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.