• 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
          • Defstobj
          • Defabsstobj
          • Stobj-table
          • Preservation-thms
          • Nested-stobjs
          • Defrstobj
          • User-stobjs-modified-warnings
          • With-global-stobj
          • Stobj-example-1
          • Defrstobj
          • Stobj-example-3
          • Stobj-example-1-proofs
          • With-local-stobj
          • Stobj-example-1-defuns
          • Declare-stobjs
          • Trans-eval-and-stobjs
          • With-local-state
          • Stobj-example-2
          • Stobj-example-1-implementation
          • Swap-stobjs
          • Resize-list
          • Nth-aliases-table
          • Trans-eval-and-locally-bound-stobjs
          • Std/stobjs
          • Count-keys
            • Update-nth-array
          • State
          • Memoize
          • Mbe
          • Io
          • Defpkg
          • Apply$
          • 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
          • 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
    • Stobj
    • ACL2-built-ins

    Count-keys

    Count the number of keys in association list

    (Count-keys al) returns the number of distinct keys in an association list.

    Count-keys has a guard of t. This function is called in the body of function, <h>-count where <h> is a hash-table field of a stobj. See defstobj.

    Function: hons-remove-assoc

    (defun hons-remove-assoc (k x)
           (declare (xargs :guard t))
           (if (atom x)
               nil
               (if (and (consp (car x))
                        (not (equal k (caar x))))
                   (cons (car x)
                         (hons-remove-assoc k (cdr x)))
                   (hons-remove-assoc k (cdr x)))))

    Function: count-keys

    (defun
         count-keys (al)
         (declare (xargs :guard t))
         (if (atom al)
             0
             (if (consp (car al))
                 (+ 1
                    (count-keys (hons-remove-assoc (caar al) (cdr al))))
                 (count-keys (cdr al)))))