• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Community
    • Proof-automation
    • ACL2
      • Theories
      • Rule-classes
      • Proof-builder
      • Recursion-and-induction
      • Hons-and-memoization
      • Events
      • Parallelism
      • History
      • Programming
      • Operational-semantics
      • Real
      • Start-here
      • Debugging
      • Miscellaneous
      • Output-controls
      • Macros
        • Make-event
        • Defmacro
        • Untranslate-patterns
        • Tc
        • Trans*
        • Macro-aliases-table
        • Macro-args
        • Defabbrev
        • User-defined-functions-table
        • Trans
        • Untranslate-for-execution
        • Add-macro-fn
        • Check-vars-not-free
        • Safe-mode
        • Macro-libraries
          • B*
          • Defunc
          • Fty
          • Apt
          • Std/util
            • Defprojection
            • Deflist
            • Defaggregate
            • Define
            • Defmapping
            • Defenum
            • Add-io-pairs
            • Defalist
            • Defmapappend
            • Returns-specifiers
            • Defarbrec
            • Defines
            • Define-sk
            • Error-value-tuples
            • Defmax-nat
            • Defmin-int
            • Deftutorial
            • Extended-formals
            • Defrule
            • Defval
            • Defsurj
            • Defiso
            • Defconstrained-recognizer
            • Deffixer
            • Defmvtypes
            • Defconsts
            • Defthm-unsigned-byte-p
            • Support
              • Extract-keywords
                • Dumb-string-sublis
                • Raise
                • Look-up-return-vals
                • Logic-mode-p
                • Look-up-wrapper-args
                • Look-up-formals
                • Legal-kwds-p
                • Split-///
                • Keyword-legality
                • Getarg+
                • Var-is-stobj-p
                • Look-up-guard
                • Getarg
                • Cons-listp
                • Tuplep
                • Tuple-listp
                • Ends-with-period-p
              • Defthm-signed-byte-p
              • Defthm-natp
              • Defund-sk
              • Defmacro+
              • Defsum
              • Defthm-commutative
              • Definj
              • Defirrelevant
              • Defredundant
            • Defdata
            • Defrstobj
            • Seq
            • Match-tree
            • Defrstobj
            • With-supporters
            • Def-partial-measure
            • Template-subst
            • Soft
            • Defthm-domain
            • Event-macros
            • Def-universal-equiv
            • Def-saved-obligs
            • With-supporters-after
            • Definec
            • Sig
            • Outer-local
            • Data-structures
          • Trans1
          • Defmacro-untouchable
          • Set-duplicate-keys-action
          • Add-macro-alias
          • Magic-macroexpand
          • Defmacroq
          • Trans!
          • Remove-macro-fn
          • Remove-macro-alias
          • Add-binop
          • Untrans-table
          • Trans*-
          • Remove-binop
          • Tcp
          • Tca
        • Mailing-lists
        • Interfacing-tools
      • Macro-libraries
        • B*
        • Defunc
        • Fty
        • Apt
        • Std/util
          • Defprojection
          • Deflist
          • Defaggregate
          • Define
          • Defmapping
          • Defenum
          • Add-io-pairs
          • Defalist
          • Defmapappend
          • Returns-specifiers
          • Defarbrec
          • Defines
          • Define-sk
          • Error-value-tuples
          • Defmax-nat
          • Defmin-int
          • Deftutorial
          • Extended-formals
          • Defrule
          • Defval
          • Defsurj
          • Defiso
          • Defconstrained-recognizer
          • Deffixer
          • Defmvtypes
          • Defconsts
          • Defthm-unsigned-byte-p
          • Support
            • Extract-keywords
              • Dumb-string-sublis
              • Raise
              • Look-up-return-vals
              • Logic-mode-p
              • Look-up-wrapper-args
              • Look-up-formals
              • Legal-kwds-p
              • Split-///
              • Keyword-legality
              • Getarg+
              • Var-is-stobj-p
              • Look-up-guard
              • Getarg
              • Cons-listp
              • Tuplep
              • Tuple-listp
              • Ends-with-period-p
            • Defthm-signed-byte-p
            • Defthm-natp
            • Defund-sk
            • Defmacro+
            • Defsum
            • Defthm-commutative
            • Definj
            • Defirrelevant
            • Defredundant
          • Defdata
          • Defrstobj
          • Seq
          • Match-tree
          • Defrstobj
          • With-supporters
          • Def-partial-measure
          • Template-subst
          • Soft
          • Defthm-domain
          • Event-macros
          • Def-universal-equiv
          • Def-saved-obligs
          • With-supporters-after
          • Definec
          • Sig
          • Outer-local
          • Data-structures
        • Interfacing-tools
        • Hardware-verification
        • Software-verification
        • Math
        • Testing-utilities
      • Support

      Extract-keywords

      Extract legal keyword/value pairs from an argument list.

      If a keyword occurs as a singleton list in legal-kwds, it may have mulitple occurrences in the args, and the result stored in the kwd-alist will be a list of the arguments to the occurrences. For example:

      (extract-keywords 'foo '((:bar)) '(:bar x :bar y) nil)

      produces ((:bar y x)) as its keyword alist result.

      Definitions and Theorems

      Function: extract-keywords

      (defun extract-keywords (ctx legal-kwds args kwd-alist)
        "Returns (mv kwd-alist other-args)"
        (declare (xargs :guard (and (legal-kwds-p legal-kwds)
                                    (alistp kwd-alist))))
        (b*
          ((__function__ 'extract-keywords)
           ((when (atom args)) (mv kwd-alist args))
           (arg1 (first args))
           ((unless (keywordp arg1))
            (b* (((mv kwd-alist other-args)
                  (extract-keywords ctx legal-kwds (cdr args)
                                    kwd-alist)))
              (mv kwd-alist (cons arg1 other-args))))
           (legality (keyword-legality arg1 legal-kwds))
           ((unless legality)
            (raise (concatenate 'string
                                "~x0: invalid keyword ~x1."
                                (if legal-kwds "  Valid keywords: ~&2."
                                  "  No keywords are valid here."))
                   ctx arg1 legal-kwds)
            (mv nil nil))
           ((when (atom (rest args)))
            (raise "~x0: keyword ~x1 has no argument."
                   ctx arg1)
            (mv nil nil))
           ((when (and (not (eq legality :multiple))
                       (assoc arg1 kwd-alist)))
            (raise "~x0: multiple occurrences of keyword ~x1."
                   ctx arg1)
            (mv nil nil))
           (value (second args))
           (kwd-alist (if (eq legality :multiple)
                          (acons arg1
                                 (cons value (cdr (assoc arg1 kwd-alist)))
                                 (remove1-assoc arg1 kwd-alist))
                        (acons arg1 value kwd-alist))))
          (extract-keywords ctx legal-kwds (cddr args)
                            kwd-alist)))