Remove all pairs with a given key from an association list
General Forms: (remove-assoc key alist) (remove-assoc key alist :test 'eql) ; same as above (eql as equality test) (remove-assoc key alist :test 'eq) ; same, but eq is equality test (remove-assoc key alist :test 'equal) ; same, but equal is equality test
Also see remove1-assoc for a similar utility that deletes only the first pair in an alist with a given key, rather than all such pairs.
The guard for a call of
See equality-variants for a discussion of the relation between
(remove-assoc-eq key alist) is equivalent to(remove-assoc key alist :test 'eq) ;
(remove-assoc-equal key alist) is equivalent to(remove-assoc key alist :test 'equal) .
In particular, reasoning about any of these primitives reduces to reasoning
about the function
Function:
(defun remove-assoc-equal (x alist) (declare (xargs :guard (alistp alist))) (cond ((endp alist) nil) ((equal x (car (car alist))) (remove-assoc-equal x (cdr alist))) (t (cons (car alist) (remove-assoc-equal x (cdr alist))))))