GNU bug report logs - #75170
add-to-alist: new function

Previous Next

Package: emacs;

Reported by: Roland Winkler <winkler <at> gnu.org>

Date: Sun, 29 Dec 2024 05:35:02 UTC

Severity: wishlist

Full log


View this message in rfc822 format

From: Thierry Volpiatto <thievol <at> posteo.net>
To: Roland Winkler <winkler <at> gnu.org>
Cc: Thierry Volpiatto <thievol <at> posteo.net>, Eli Zaretskii <eliz <at> gnu.org>, Andrea Corallo <acorallo <at> gnu.org>, Stefan Kangas <stefankangas <at> gmail.com>, 75170 <at> debbugs.gnu.org
Subject: bug#75170: add-to-alist: new function
Date: Mon, 20 Jan 2025 10:06:00 +0000
[Message part 1 (text/plain, inline)]
Roland Winkler <winkler <at> gnu.org> writes:

> On Sun, Jan 19 2025, Thierry Volpiatto wrote:
>> While you are at it why not implementing a add-to-(a)list function that
>> add/remove an elemnt at INDEX in list?
>> It is what I am providing for my users in Helm.
>>
>> (setq example '((a . 1) (b . 6) (c . 3) (d . 4)))
>>
>> (helm-add-to-list 'example '(b . 2) 1 'replace)
>>
>> =>((a . 1) (b . 2) (c . 3) (d . 4))
>
> I am just curious: when can this be useful?

Also the usage of an index allows things like this (what you asked in
first place):

(setq A '((foo . bar) (bar . test) (baz . else)))
(helm-add-to-list 'A '(foo . baz) (cl-position (assoc 'bar A) A) t)
=>((foo . bar) (foo . baz) (baz . else))

-- 
Thierry
[signature.asc (application/pgp-signature, inline)]

This bug report was last modified 142 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.