[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: inverse of add-to-list: remove-from-list
From: |
Boruch Baum |
Subject: |
Re: inverse of add-to-list: remove-from-list |
Date: |
Tue, 13 Oct 2020 15:34:00 -0400 |
User-agent: |
NeoMutt/20180716 |
> 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'.
2] That really could/should be made clearer in the docstring; something
like:
"If SEQ is a list, the original symbol is modified in place, ie.
destructively. If SEQ is not a list, eg. a vector or string, this
function creates and returns a new vector or string, and you must
explicitly ‘(setq foo (delete element foo))’ to alter the original."
If there's agreement on this docstring change, can it be committed?
3] Emacs also offers a more flexible function `cl-delete'. See there.
--
hkp://keys.gnupg.net
CA45 09B5 5351 7C11 A9D1 7286 0036 9E45 1595 8BC0
- Re: inverse of add-to-list: remove-from-list,
Boruch Baum <=