• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
      • Std/lists
      • Std/alists
      • Obags
      • Std/util
      • Std/strings
        • Pretty-printing
        • Printtree
        • Base64
        • Charset-p
          • Defcharset
            • Count-leading-charset
            • Str-count-leading-charset-fast
            • Str-count-leading-charset
            • Chars-in-charset-p
            • Code-in-charset-p
            • Char-in-charset-p
          • Strtok!
          • Cases
          • Concatenation
          • Html-encoding
          • Character-kinds
          • Substrings
          • Strtok
          • Equivalences
          • Url-encoding
          • Lines
          • Explode-implode-equalities
          • Ordering
          • Numbers
          • Pad-trim
          • Coercion
          • Std/strings/digit-to-char
          • Substitution
          • Symbols
        • Std/osets
        • Std/io
        • Std/basic
        • Std/system
        • Std/typed-lists
        • Std/bitsets
        • Std/testing
        • Std/typed-alists
        • Std/stobjs
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Charset-p

    Defcharset

    Define a recognizer for a particular set of characters.

    Defcharset is a macro for introducing a charset-p and proving that it recognizes the correct characters.

    Example
    (defcharset whitespace
      (or (eql x #\Newline)
          (eql x #\Space)
          (eql x #\Tab)))

    This example introduces:

    • (whitespace-char-p x) — a "slow" function for recognizing newline, space, and tab characters
    • (whitespace-chars) — a charset-p that is proven to correspond to whitespace-char-p,
    • (whitespace-charlist-p x) — an ordinary std::deflist to recognize lists whose every character satisfies whitespace-char-p.
    General Form
    (defcharset prefix criteria
      [:in-package-of package]
      [:parents ...]
      [:short ...]
      [:long ...]

    All functions will be introduced in pkg, determined as follows:

    • If an :in-package-of argument is provided, then the corresponding package must be a symbol, and we will use its package.
    • Otherwise, the package of prefix will be used.

    The prefix is a symbol that is used for name generation. Some common examples would be whitespace, alpha, digit, etc.

    The criteria is some term involving the variable pkg::x. The criteria term may assume that x is a character, and is responsible for determining whether x is a member of the desired set. Normally you should not worry about the efficiency of criteria. Although the term you write here does become part of recognizers like whitespace-char-p and whitespace-charlist-p, the actual character set, i.e., whitespace-chars, is represented as a bit mask, and the speed of your criteria term will not have any bearing on how fast it is to look up its bits.

    The :parents, :short, and :long options are as in defxdoc, and allow you to provide documentation to the character recognizer, e.g., whitespace-char-p. The other functions are documented automatically.