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

From: "Alfred M. Szmidt" <[email-masked]>
Date: Tue, 21 Jan 2025 04:06:34 -0500

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

Why should it work on alists at all?  map-put! assumes a map (where is
this structure documented? I did not see anything in the Elisp
manual), not an alist.  Invalid alists will also not work on functions
that assume alists.

(assoc-delete-all 1 '(1 (2 . 3))) does not delete 1.

       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.

   Robert
   --