GNU bug report logs - #75170
add-to-alist: new function

Previous Next

Package: emacs;

Reported by: Roland Winkler <winkler <at> gnu.org>

Date: Sun, 29 Dec 2024 05:35:02 UTC

Severity: wishlist

Full log


View this message in rfc822 format

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Robert Pluim <rpluim <at> gmail.com>
Cc: 75170 <at> debbugs.gnu.org, Eli Zaretskii <eliz <at> gnu.org>, acorallo <at> gnu.org, Roland Winkler <winkler <at> gnu.org>, Stefan Monnier <monnier <at> gnu.org>
Subject: bug#75170: add-to-alist: new function
Date: Tue, 21 Jan 2025 10:47:13 -0800
Robert Pluim <rpluim <at> gmail.com> writes:

>>>>>> On Mon, 20 Jan 2025 15:40:48 -0600, Stefan Kangas <stefankangas <at> gmail.com> said:
>
>     Stefan> I'm curious to hear more opinions about `map-put!`.  I'm also copying in
>     Stefan> Stefan Monnier, who added that function (or at least named it).
>
> map-put! does not work well with alists that are not 'proper':
>
>     ELISP> (setq x (list 1 '(2 . 3)))
>     (1 (2 . 3))
>
>     ELISP> (map-put! x 2 4)
>     4
>      (#o4, #x4, ?\C-d)
>     ELISP> x
>     (1 (2 . 3) 2 4)
>
>     ELISP> (alist-get 2 x)
>     3
>      (#o3, #x3, ?\C-c)
>     ELISP> (setf (alist-get 2 x) 5)
>     5
>      (#o5, #x5, ?\C-e)
>     ELISP> x
>     (1 (2 . 5) 2 4)
>
> If the intent is to have something thatʼs easy to use and footgun-free
> for beginners, then I donʼt think `map-put!' is it.

Thanks, I think this and the subsequent discussion shows that you're
right about that.

So `map-put!` is not a good alternative to `add-to-alist`.  I don't
think generalized variables are either, not for something intended for
end-users and not developers (as `add-to-list` is).

What are we left with?  Maybe we should just add `add-to-alist`.




This bug report was last modified 143 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.