• Top
    • Documentation
    • Books
    • Recursion-and-induction
    • Boolean-reasoning
    • Debugging
    • Projects
    • 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
        • 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
        • System-attachments
        • Developers-guide
        • 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
          • Std/strings
          • String-listp
          • Stringp
          • Length
          • Search
          • Remove-duplicates
          • Position
          • Coerce
          • Concatenate
          • Reverse
          • String
            • Subseq
            • Substitute
            • Count
            • Char
            • String-downcase
            • String-upcase
            • String<
            • String-equal
            • String-utilities
            • String-append
            • String>=
            • String<=
            • String>
            • Hex-digit-char-theorems
            • String-downcase-gen
            • String-upcase-gen
          • 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
    • Strings
    • ACL2-built-ins

    String

    coerce to a string

    (String x) coerces x to a string.

    The guard for string requires its argument to be a string, a symbol, or a character.

    • If x is already a string, then it is returned unchanged.
    • If x is a symbol, then its symbol-name is returned.
    • If x is a character, the corresponding one-character string is returned.

    Note: this is a rather low-level operation that doesn't support coercing numbers or conses into strings. If you want to turn numbers into strings, see functions such as str::nat-to-dec-string, or more generally the str::numbers functions. For conses, see the str::pretty-printing routines such as str::pretty.

    String is a Common Lisp function. See any Common Lisp documentation for more information.

    Function: string

    (defun string (x)
           (declare (xargs :guard (or (stringp x)
                                      (symbolp x)
                                      (characterp x))))
           (cond ((stringp x) x)
                 ((symbolp x) (symbol-name x))
                 (t (coerce (list x) 'string))))