;; Scraps of code having to do with deletion that I never ended up ;; using anywhere. ;; Author: Michael Olson (mwolson AT gnu.org) (defun delete-from-list (predicate closure seq) "Remove all items satisfying PREDICATE in SEQ. This is a destructive function: it reuses the storage of SEQ whenever possible. PREDICATE is called with CLOSURE as its first argument and an element of SEQ as its second argument." ;; remove from car (while (when (funcall predicate closure (car seq)) (setq seq (cdr seq)))) ;; remove from cdr (let ((ptr seq) (next (cdr seq))) (while next (when (funcall predicate closure (car next)) (setcdr ptr (if (consp next) (cdr next) nil))) (setq ptr (cdr ptr)) (setq next (cdr ptr)))) seq) (defun delete-duplicates (list &optional accessor) "Destructively remove `equal' duplicates from LIST. Store the result in LIST and return it. LIST must be a proper list. Of several `equal' occurrences of an element in LIST, the first one is kept. If ACCESSOR is non-nil, it is applied to each element before the comparison." (unless accessor (setq accessor #'identity)) (let ((tail list)) (while tail (setcdr tail (muse-delete-from-list (lambda (closure second) (let ((first (car closure)) (accessor (cdr closure))) (equal first (funcall accessor second)))) (cons (funcall accessor (car tail)) accessor) (cdr tail))) (setq tail (cdr tail))) list)) (defun alist-disjoint (keys alist) "Remove each key in KEYS from ALIST." (setq alist (copy-alist alist)) (dolist (key keys) ;; remove from car (while (when (equal key (caar alist)) (setq alist (cdr alist)))) ;; remove from cdr (let ((cur (cadr alist)) (prev alist)) (while cur (if (equal key (car cur)) (setcdr prev (cddr prev)) (setq prev (cdr prev))) (setq cur (cadr prev))))) alist)