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

From: Michael Heerdegen <[email-masked]>
Date: Mon, 20 Jan 2025 14:42:46 +0100

Roland Winkler <[email-masked]> writes:

> Why is it not enough to specify the key of the association that is
> supposed to be removed from an alist?  What is the purpose of making the
> removal of an association also dependent on the values of DEFAULT and the
> 2nd arg for setf?

Please do not limit your considerations to this special case.  DEFAULT
and the second arg of setf are different things.  The expression you
setf to is not necessarily a constant:

  (setf (alist-get ...) (get-the-element)).

About your second question: Please also think about the general case.

The promise of (setf PLACE VAL) is that VAL will be stored in PLACE
after the operation.  The REMOVE arg just means: it is allowed to
achieve that by removing an association when appropriate.

(alist-get ... DEFAULT ...) will return DEFAULT
when an element is not present.  If we setf to a different value we
can't remove anything from the alist because our promise would not hold
and it would not be appropriate.

Michael.