• Top
    • Documentation
    • Books
    • Recursion-and-induction
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
      • Std/lists
      • Std/alists
      • Obags
      • Std/util
      • Std/strings
      • Std/io
        • Open-channel-lemmas
        • Std/io/read-char$
        • Std/io/read-object
        • Std/io/open-output-channel
        • Unsound-read
        • Read-string
        • Read-bytes$
        • File-measure
        • Read-bytes$-n
        • Std/io/read-byte$
        • Std/io/open-input-channel
        • Print-compressed
        • Read-file-lines-no-newlines
        • Nthcdr-bytes
        • Read-file-lines
        • Std/io/close-output-channel
        • Read-file-characters
        • Read-file-bytes
        • Print-legibly
        • Std/io/close-input-channel
        • Read-file-objects
        • Logical-story-of-io
        • Take-bytes
        • Std/io/peek-char$
        • Read-file-characters-rev
        • Read-file-as-string
          • Std/io/write-byte$
          • Std/io/set-serialize-character
          • Std/io/print-object$
          • Std/io/princ$
          • Std/io/read-file-into-string
          • *file-types*
        • Std/osets
        • Std/system
        • Std/basic
        • Std/typed-lists
        • Std/bitsets
        • Std/testing
        • Std/typed-alists
        • Std/stobjs
        • Std-extensions
      • Proof-automation
      • Macro-libraries
      • ACL2
      • Interfacing-tools
      • Hardware-verification
      • Software-verification
      • Testing-utilities
      • Math
    • Std/io

    Read-file-as-string

    Signature
    (read-file-as-string filename state) → (mv contents/nil state)
    Arguments
    filename — Guard (stringp filename).
    Returns
    contents/nil — On success: the entire contents of the file as an ordinary string. On failure, e.g., because filename does not exist: nil.
        Type (or (stringp contents/nil) (not contents/nil)).

    This is just a wrapper around read-file-characters. We leave it enabled.

    Definitions and Theorems

    Function: read-file-as-string

    (defun
       read-file-as-string (filename state)
       (declare (xargs :stobjs (state)))
       (declare (xargs :guard (stringp filename)))
       (let ((__function__ 'read-file-as-string))
            (declare (ignorable __function__))
            (mbe :logic (b* (((mv chars state)
                              (read-file-characters filename state)))
                            (mv (and (not (stringp chars))
                                     (implode chars))
                                state))
                 :exec (b* (((mv rchars state)
                             (read-file-characters-rev filename state)))
                           (mv (and (not (stringp rchars))
                                    (str::rchars-to-string rchars))
                               state)))))

    Theorem: return-type-of-read-file-as-string.contents/nil

    (defthm return-type-of-read-file-as-string.contents/nil
            (b* (((mv ?contents/nil ?state)
                  (read-file-as-string filename state)))
                (or (stringp contents/nil)
                    (not contents/nil)))
            :rule-classes :type-prescription)