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

From: Thierry Volpiatto <[email-masked]>
Date: Mon, 20 Jan 2025 10:06:00 +0000

Roland Winkler <[email-masked]> 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