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

From: Roland Winkler <[email-masked]>
Date: Tue, 21 Jan 2025 23:09:42 -0600

On Tue, Jan 21 2025, Stefan Monnier wrote:
> I don't have much to add to this discussion except:
>
> - I personally dislike `add-to-list` because I think that conflating
>   symbols with variables is a bad practice (e.g. because it is
>   incompatible with lexical scoping).
>
> - Yet, it works OK for configuration, which always involves
>   global/dynamic variables anyway, and where `push` is not great and
>   `cl-pushnew` often requires `:test #'equal`.
>
> - I think we should try and provide better support (in general) for
>   unloading packages, and this means improving support for undoing
>   top-level operations.  We currently support `defalias` and friends
>   fairly well, `defvar` and friends tolerably, but we fail miserably for
>   most other things.  So maybe something like an `add-to-alist` dedicated
>   to top-level operations, which records the change somewhere
>   (e.g. `load-history`) so we can undo it when unloading, would be
>   an improvement.  Of course it would make a lot of sense to do it
>   together with similar operations to add an element to a list, to add
>   a property to a symbol, to add an advice, to add a function on a hook,
>   ... so it's probably worth thinking of a more general way to provide
>   those operations than doing it one at a time.

In an ideal world, the last item in your list would be great.  But if
dreaming of an ideal world should imply that nothing is going to improve
in a foreseeable future, then I am in favor of less-than-ideal solutions
that can be implemented more easily.