all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Re: inverse of add-to-list: remove-from-list
@ 2020-10-13 19:34 Boruch Baum
  2020-10-13  8:42 ` Uwe Brauer
  2020-10-13 20:01 ` Andreas Schwab
  0 siblings, 2 replies; 14+ messages in thread
From: Boruch Baum @ 2020-10-13 19:34 UTC (permalink / raw)
  To: Emacs-Devel List

> 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



^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2020-10-16 11:14 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-13 19:34 inverse of add-to-list: remove-from-list Boruch Baum
2020-10-13  8:42 ` Uwe Brauer
2020-10-13  9:09   ` Andreas Schwab
2020-10-13  9:34     ` Thibaut Verron
2020-10-13 11:24       ` Uwe Brauer
2020-10-13 13:57   ` Stefan Monnier
2020-10-14  5:58     ` Thibaut Verron
2020-10-15 15:28       ` Uwe Brauer
2020-10-15 16:31       ` Stefan Monnier
2020-10-16 11:14         ` Thibaut Verron
2020-10-14  5:28   ` Teemu Likonen
2020-10-13 20:01 ` Andreas Schwab
2020-10-13 20:07   ` Boruch Baum
2020-10-13 20:41     ` Andreas Schwab

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.