[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: inverse of add-to-list: remove-from-list
From: |
Andreas Schwab |
Subject: |
Re: inverse of add-to-list: remove-from-list |
Date: |
Tue, 13 Oct 2020 22:01:18 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) |
On Okt 13 2020, Boruch Baum wrote:
>> On Okt 13 2020, Uwe Brauer wrote:
>> > But there is, as far as I know, no inverse functionality
>
> 1] Similar to what Andreas suggested, try this:
>
> (let ((aa '(1 2 3 1 4 1 2)))
> (delete 2 aa)
> aa)
>
> And note that the fine distinction made in the docstring for the
> `delete' function:
>
> "If SEQ is not a list, deletion is never performed destructively;
> instead this function creates and returns a new vector or string.
>
> Write ‘(setq foo (delete element foo))’ to be sure of correctly
> changing the value of a sequence ‘foo’.
>
> So, in the case of SEQ being a list, there is no need to `setq foo'.
This is not true. If the element to delete is the first element of the
list, it returns the cdr of the list.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."