Function: assoc-delete-all

assoc-delete-all is a byte-compiled function defined in subr.el.gz.

Signature

(assoc-delete-all KEY ALIST &optional TEST)

Documentation

Delete from ALIST all elements whose car is KEY.

Compare keys with TEST. Defaults to equal. Return the modified alist. Elements of ALIST that are not conses are ignored.

Other relevant functions are documented in the list and alist groups.

View in manual

Probably introduced at or before Emacs version 21.1.

Shortdoc

;; alist
(assoc-delete-all "b" (list '("a" . a) '("b" . b) '("b" . c)))
    => (("a" . a))
;; list
(assoc-delete-all "b" (list '("a" . a) '("b" . b) '("b" . c)))
    => (("a" . a))

Aliases

org-assoc-delete-all

Source Code

;; Defined in /usr/src/emacs/lisp/subr.el.gz
(defun assoc-delete-all (key alist &optional test)
  "Delete from ALIST all elements whose car is KEY.
Compare keys with TEST.  Defaults to `equal'.
Return the modified alist.
Elements of ALIST that are not conses are ignored."
  (declare (important-return-value t))
  (unless test (setq test #'equal))
  (while (and (consp (car alist))
	      (funcall test (caar alist) key))
    (setq alist (cdr alist)))
  (let ((tail alist) tail-cdr)
    (while (setq tail-cdr (cdr tail))
      (if (and (consp (car tail-cdr))
	       (funcall test (caar tail-cdr) key))
	  (setcdr tail (cdr tail-cdr))
	(setq tail tail-cdr))))
  alist)