• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Community
    • Proof-automation
    • Macro-libraries
    • ACL2
      • Theories
      • Rule-classes
      • Proof-builder
      • Recursion-and-induction
      • Hons-and-memoization
      • Events
      • Parallelism
      • History
      • Programming
        • Defun
        • Declare
        • System-utilities
        • Stobj
        • State
        • Mutual-recursion
        • Memoize
        • Mbe
        • Io
        • Defpkg
        • Apply$
        • Loop$
        • Programming-with-state
        • Arrays
        • Characters
          • Character-listp
          • Characterp
          • Coerce
          • Digit-char-p
            • Code-char
            • Char-code
            • Char-upcase
            • Char-downcase
            • Standard-char-p
            • Char
            • Alpha-char-p
            • Upper-case-p
            • Lower-case-p
            • Explode-nonnegative-integer
            • Explode-atom
            • Char-equal
            • Digit-to-char
            • Char<
            • Char>=
            • Make-character-list
            • Char>
            • Char<=
            • Standard-char-listp
            • Character-alistp
            • Standard-char-p+
            • Chars-upcase-gen
            • Chars-downcase-gen
            • Char-upcase-gen
            • Char-downcase-gen
          • Time$
          • Defconst
          • Defmacro
          • Loop$-primer
          • Fast-alists
          • Evaluation
          • Guard
          • Equality-variants
          • Compilation
          • Hons
          • ACL2-built-ins
          • Developers-guide
          • System-attachments
          • Advanced-features
          • Set-check-invariant-risk
          • Numbers
          • Efficiency
          • Irrelevant-formals
          • 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
          • Oracle-eval
          • Defmacro-untouchable
          • <<
          • Primitive
          • Revert-world
          • Unmemoize
          • Set-duplicate-keys-action
          • Symbols
          • Def-list-constructor
          • Easy-simplify-term
          • Defiteration
          • Fake-oracle-eval
          • Defopen
          • Sleep
        • Operational-semantics
        • Real
        • Start-here
        • Debugging
        • Miscellaneous
        • Output-controls
        • Macros
        • Interfacing-tools
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Characters
    • ACL2-built-ins

    Digit-char-p

    The number, if any, corresponding to a given character

    (digit-char-p ch) is the integer corresponding to the character ch in base 10. For example, (digit-char-p #\3) is equal to the integer 3. More generally, an optional second argument specifies the radix (default 10, as indicated above).

    The guard for digit-char-p (more precisely, for the function our-digit-char-p that calls of this macro expand to) requires its second argument to be an integer between 2 and 36, inclusive, and its first argument to be a character.

    Digit-char-p is a Common Lisp function, though it is implemented in the ACL2 logic as an ACL2 macro. See any Common Lisp documentation for more information.

    Macro: digit-char-p

    (defmacro digit-char-p (ch &optional (radix '10))
      (cons 'our-digit-char-p
            (cons ch (cons radix 'nil))))

    Function: our-digit-char-p

    (defun our-digit-char-p (ch radix)
      (declare (xargs :guard (and (characterp ch)
                                  (integerp radix)
                                  (<= 2 radix)
                                  (<= radix 36))))
      (let ((l (assoc ch
                      '((#\0 . 0)
                        (#\1 . 1)
                        (#\2 . 2)
                        (#\3 . 3)
                        (#\4 . 4)
                        (#\5 . 5)
                        (#\6 . 6)
                        (#\7 . 7)
                        (#\8 . 8)
                        (#\9 . 9)
                        (#\a . 10)
                        (#\b . 11)
                        (#\c . 12)
                        (#\d . 13)
                        (#\e . 14)
                        (#\f . 15)
                        (#\g . 16)
                        (#\h . 17)
                        (#\i . 18)
                        (#\j . 19)
                        (#\k . 20)
                        (#\l . 21)
                        (#\m . 22)
                        (#\n . 23)
                        (#\o . 24)
                        (#\p . 25)
                        (#\q . 26)
                        (#\r . 27)
                        (#\s . 28)
                        (#\t . 29)
                        (#\u . 30)
                        (#\v . 31)
                        (#\w . 32)
                        (#\x . 33)
                        (#\y . 34)
                        (#\z . 35)
                        (#\A . 10)
                        (#\B . 11)
                        (#\C . 12)
                        (#\D . 13)
                        (#\E . 14)
                        (#\F . 15)
                        (#\G . 16)
                        (#\H . 17)
                        (#\I . 18)
                        (#\J . 19)
                        (#\K . 20)
                        (#\L . 21)
                        (#\M . 22)
                        (#\N . 23)
                        (#\O . 24)
                        (#\P . 25)
                        (#\Q . 26)
                        (#\R . 27)
                        (#\S . 28)
                        (#\T . 29)
                        (#\U . 30)
                        (#\V . 31)
                        (#\W . 32)
                        (#\X . 33)
                        (#\Y . 34)
                        (#\Z . 35)))))
        (cond ((and l (< (cdr l) radix)) (cdr l))
              (t nil))))