unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Roland Winkler <winkler@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 75170@debbugs.gnu.org
Subject: bug#75170: add-to-alist: new function
Date: Sun, 29 Dec 2024 08:50:18 -0600	[thread overview]
Message-ID: <87zfkelf11.fsf@gnu.org> (raw)
In-Reply-To: <86cyhbq66r.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 29 Dec 2024 09:50:04 +0200")

On Sun, Dec 29 2024, Eli Zaretskii wrote:
> What is the advantage of adding this function, given that add-to-list
> can be used with alists, and given that alist-get can nowadays be used
> as a generalize variable?

The advantage I see for also having the function add-to-alist is the
following:

add-to-list checks for the presence of an element in a list.  In the
case of alists, this means it checks for the presence of associations.
You cannot easily modify an existing association with add-to-list.  If
you have an alist with association (foo . bar) and you call add-to-list
with an element (foo . baz), add-to-list will not remove the association
(foo . bar), but the alist will then contain both associations.

add-to-alist checks for the presence of keys and it makes sure that each
key appears only once in an alist.  By default, it replaces the value of
an existing key.  This makes it easy to modify an existing association.
Only with the optional arg NO-REPLACE non-nil, it will preserve an
existing association.

Say, I want in my .emacs file a more complicated association for a key,
and I do not get initially what I want.  I can call add-to-alist
multiple times, till I get what I want.

Is there a simple way to accomplish this in other ways (a way that we
recommend for users in their init file if they do not want to use
customize like me)?

Would it make sense to give this functions a different name if more
often it may be used to modify existing associations in an alist instead
of adding new ones?





      reply	other threads:[~2024-12-29 14:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-29  5:33 bug#75170: add-to-alist: new function Roland Winkler
2024-12-29  6:34 ` Roland Winkler
2024-12-29  7:54   ` Juri Linkov
2024-12-29 14:54     ` Roland Winkler
2024-12-29  7:33 ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-29  7:50 ` Eli Zaretskii
2024-12-29 14:50   ` Roland Winkler [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zfkelf11.fsf@gnu.org \
    --to=winkler@gnu.org \
    --cc=75170@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).