From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Roland Winkler Newsgroups: gmane.emacs.bugs Subject: bug#75170: add-to-alist: new function Date: Sun, 29 Dec 2024 08:50:18 -0600 Message-ID: <87zfkelf11.fsf@gnu.org> References: <878qrzm4sb.fsf@gnu.org> <86cyhbq66r.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5025"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 75170@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Dec 29 15:51:28 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tRuda-00018d-Gf for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 29 Dec 2024 15:51:26 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tRudE-0003M2-5t; Sun, 29 Dec 2024 09:51:04 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tRudC-0003Lr-Bg for bug-gnu-emacs@gnu.org; Sun, 29 Dec 2024 09:51:02 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tRudC-00045p-3Q for bug-gnu-emacs@gnu.org; Sun, 29 Dec 2024 09:51:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=LDa1wVBpKOVjTYaVnHqhFtkG5t1mSjTz9ywnxNarvFo=; b=Nq9qmqD7gEWgOiZwQxM20ggENJVp7m1/JBEa9uNaLzwHiHMJWtkDewin9YRn4PSe1pwNyYatHYcr0ImPsHJuZSP66zXkbWnkBXU6/XTtH0SK/3MTMwjpoYisVWtDLqh8NdOGYtbdyjFWj/PcU371l9C7UtP35zogRqJrxjXVE29gbNXufQ0vF/coVT6tfVONEyNAEePFUdh9GiwOlDxDUCmJSeazSNfyL4qm2nLXj3D5+ipt8QykCuW1F9z27PVD7pVwIKKJdC97fI0HLKjubVZgQuCO+hcY1lVbqbmoXIT1G8QieaDWGyVZDj9ME9l78LHcHjhqGo/2PbFIpqHVwQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tRudB-0003l9-SS for bug-gnu-emacs@gnu.org; Sun, 29 Dec 2024 09:51:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Roland Winkler Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 29 Dec 2024 14:51:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 75170 X-GNU-PR-Package: emacs Original-Received: via spool by 75170-submit@debbugs.gnu.org id=B75170.173548382814407 (code B ref 75170); Sun, 29 Dec 2024 14:51:01 +0000 Original-Received: (at 75170) by debbugs.gnu.org; 29 Dec 2024 14:50:28 +0000 Original-Received: from localhost ([127.0.0.1]:54329 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tRuce-0003kI-0X for submit@debbugs.gnu.org; Sun, 29 Dec 2024 09:50:28 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:57236) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tRucb-0003jr-Tp for 75170@debbugs.gnu.org; Sun, 29 Dec 2024 09:50:26 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tRucW-00043W-Me for 75170@debbugs.gnu.org; Sun, 29 Dec 2024 09:50:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=LDa1wVBpKOVjTYaVnHqhFtkG5t1mSjTz9ywnxNarvFo=; b=Vd95aIHPNa/5YgcKPr58 QlIRiRUku1AP83qbeUoc9QKuau8rgbgRoSqXlE3y0j3c6/Y8WMHbnXEshNdm9JdMeFVJ4j6VwSMhO dOD7/+pZFPBWx4u6XGJeYuQ1VnYwE+uCcLfyKsv5K7/yOfhpD/ZZlYgZGF0jV0k9UNIRNLaBHwqJV zolSJxgSLEz/iwCak0HpBrfxLAAnrYnrOGuG073dzAPKL2+TindRBjgUUGA1ZqgH4a2OvdQhMhBDs gCsEULMVhVbnzMtcV9d2243BvUhoG1mgfGyxBqHCecTTHlN/LCD5HJr2MCOPsws2fI1q3U7Pj3zHd sHaIl5mMO2j+WA==; In-Reply-To: <86cyhbq66r.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 29 Dec 2024 09:50:04 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:297947 Archived-At: 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?