• Top
    • Documentation
    • Books
    • Recursion-and-induction
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
      • Theories
      • Rule-classes
      • Proof-builder
      • Hons-and-memoization
      • Events
      • History
      • Parallelism
      • Programming
        • Defun
        • Declare
        • System-utilities
        • Stobj
        • State
        • Memoize
        • Mbe
        • Io
        • Apply$
        • Defpkg
        • Mutual-recursion
        • Loop$
        • Programming-with-state
        • Arrays
        • Characters
        • Time$
        • Loop$-primer
        • Fast-alists
        • Defmacro
        • Defconst
        • Evaluation
        • Guard
        • Equality-variants
        • Compilation
        • Hons
        • ACL2-built-ins
        • Developers-guide
        • System-attachments
        • Advanced-features
        • Set-check-invariant-risk
        • Numbers
        • Irrelevant-formals
        • Efficiency
        • Introduction-to-programming-in-ACL2-for-those-who-know-lisp
        • Redefining-programs
        • Lists
        • Invariant-risk
        • Errors
        • Defabbrev
        • Conses
        • Alists
          • Std/alists
          • Omaps
          • Fast-alists
          • Alistp
          • Misc/records
          • Remove-assocs
          • Assoc
          • Symbol-alistp
          • Rassoc
          • Remove-assoc
            • Std/alists/remove-assoc-equal
          • Remove1-assoc
          • Alist-map-vals
          • Depgraph
          • Alist-map-keys
          • Put-assoc
          • Strip-cars
          • Pairlis$
          • Strip-cdrs
          • Sublis
          • Acons
          • Eqlable-alistp
          • Assoc-string-equal
          • Standard-string-alistp
          • Alist-to-doublets
          • Character-alistp
          • Alist-keys-subsetp
          • R-symbol-alistp
          • R-eqlable-alistp
          • Pairlis
          • Pairlis-x2
          • Pairlis-x1
          • Delete-assoc
        • Set-register-invariant-risk
        • Strings
        • Program-wrapper
        • Get-internal-time
        • Basics
        • Packages
        • Defmacro-untouchable
        • Primitive
        • <<
        • Revert-world
        • Set-duplicate-keys-action
        • Unmemoize
        • Symbols
        • Def-list-constructor
        • Easy-simplify-term
        • Defiteration
        • Defopen
        • Sleep
      • Start-here
      • Real
      • Debugging
      • Miscellaneous
      • Output-controls
      • Macros
      • Interfacing-tools
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
    • Testing-utilities
    • Math
  • Alists
  • ACL2-built-ins

Remove-assoc

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

(Remove-assoc key alist) returns an alist that is the same as the list alist, except that all pairs in alist with a car of key are deleted (if any; otherwise alist is returned). Note that the order of the elements of alist is unchanged (though some may be deleted).

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 remove-assoc depends on the test. In all cases, the second argument must satisfy alistp. If the test is eql, then either the first argument must be suitable for eql (see eqlablep) or the second argument must satisfy eqlable-alistp. If the test is eq, then either the first argument must be a symbol or the second argument must satisfy symbol-alistp.

See equality-variants for a discussion of the relation between remove-assoc and its variants:

(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 remove-assoc-equal.

Function: remove-assoc-equal

(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))))))

Subtopics

Std/alists/remove-assoc-equal
Theorems about remove-assoc-equal in the std/alists library.