[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: assoc-delete-all

From: Juanma Barranquero
Subject: Re: assoc-delete-all
Date: Sun, 3 Jul 2005 02:52:34 +0200

> 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",


reply via email to

[Prev in Thread] Current Thread [Next in Thread]