unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Juanma Barranquero <lekktu@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: assoc-delete-all
Date: Sun, 3 Jul 2005 02:52:34 +0200	[thread overview]
Message-ID: <f7ccd24b05070217522c17a52@mail.gmail.com> (raw)
In-Reply-To: <42C7300C.8050104@student.lu.se>

> There is an assq-delete-all, but I am missing assoc-delete-all ... or,
> am I missing something (else)?

If I had to guess, I'd say that is because `assq-delete-all' has only
one reasonable behavior, i.e., as it modifies the structure, you
usually are going to do

  (setq alist (assq-delete-all 'my-key alist))

or directly construct the alist, filter it through `assq-delete-all'
and then discard it.

With `assoc-delete-all' you have to decide whether you want a shallow
or a deep copy, for example:

  (defun assoc-delete-all (key alist)
   (let (l)
     (while alist
       (unless (and (consp (car alist))
                    (eq key (caar alist)))
         (setq l (cons (car alist) l)))
       (setq alist (cdr alist)))
     (nreverse l)))

will do what you want, but it will still share conses with the
original list. Other implementations can use `copy-tree' or
`copy-alist', but really, there's no one answer that is good for every
situation. Kent M. Pitman did a wonderful article about this issue (he
was speaking of copy) a long time ago: "The Best of Intentions: EQUAL
Rights--and Wrongs--in Lisp",
http://www.nhplace.com/kent/PS/EQUAL.html

-- 
                    /L/e/k/t/u

  reply	other threads:[~2005-07-03  0:52 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-03  0:23 assoc-delete-all Lennart Borgman
2005-07-03  0:52 ` Juanma Barranquero [this message]
2005-07-03  7:30   ` assoc-delete-all Lennart Borgman
2005-07-03 10:24 ` assoc-delete-all Lute Kamstra
2005-07-03 10:51   ` assoc-delete-all Lennart Borgman
2005-07-03 10:58   ` assoc-delete-all Lennart Borgman
2005-07-03 20:43 ` assoc-delete-all Richard M. Stallman
2005-07-04  0:16   ` assoc-delete-all Juri Linkov
2005-07-04  9:00     ` assoc-delete-all Juanma Barranquero
2005-07-05  5:33       ` assoc-delete-all Juri Linkov
2005-07-05  4:35     ` assoc-delete-all Richard M. Stallman
2005-07-05  5:27       ` assoc-delete-all Juri Linkov

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=f7ccd24b05070217522c17a52@mail.gmail.com \
    --to=lekktu@gmail.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).