unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Boruch Baum <boruch_baum@gmx.com>
To: Emacs-Devel List <emacs-devel@gnu.org>
Subject: Re: inverse of add-to-list: remove-from-list
Date: Tue, 13 Oct 2020 15:34:00 -0400	[thread overview]
Message-ID: <20201013193400.uqm2ng6rgfnsei2w@E15-2016.optimum.net> (raw)

> 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



             reply	other threads:[~2020-10-13 19:34 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-13 19:34 Boruch Baum [this message]
2020-10-13  8:42 ` inverse of add-to-list: remove-from-list 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201013193400.uqm2ng6rgfnsei2w@E15-2016.optimum.net \
    --to=boruch_baum@gmx.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).