• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
      • Std/lists
      • Std/alists
      • Obags
      • Std/util
      • Std/strings
      • Std/osets
      • 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
        • Read-file-lines-no-newlines
        • Print-compressed
        • 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
          • Read-object-all
        • 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/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
  • Std/io

Read-file-objects

Read an entire file into a list of ACL2 objects.

Signature: (read-file-objects filename state) returns (mv contents state).

On success, contents is a true-listp of ACL2 objects that have were found in the file, obtained by repeatedly calling read-object.

On failure, e.g., perhaps filename does not exist, contents will be a stringp saying that we failed to open the file.

Definitions and Theorems

Function: read-file-objects

(defun read-file-objects (filename state)
  "Returns (MV ERRMSG/OBJECTS STATE)"
  (declare (xargs :guard (and (state-p state)
                              (stringp filename))))
  (b* ((filename (mbe :logic (if (stringp filename) filename "")
                      :exec filename))
       ((mv channel state)
        (open-input-channel filename
                            :object state))
       ((unless channel)
        (mv (concatenate 'string
                         "Error opening file " filename)
            state))
       ((mv data state)
        (read-object-all channel state))
       (state (close-input-channel channel state)))
    (mv data state)))

Theorem: state-p1-of-read-file-objects

(defthm state-p1-of-read-file-objects
 (implies (force (state-p1 state))
          (state-p1 (mv-nth 1 (read-file-objects filename state)))))

Theorem: true-listp-of-read-file-objects

(defthm true-listp-of-read-file-objects
  (equal
       (true-listp (mv-nth 0 (read-file-objects filename state)))
       (not (stringp (mv-nth 0
                             (read-file-objects filename state))))))

Theorem: type-of-read-file-objects

(defthm type-of-read-file-objects
  (or (stringp (mv-nth 0 (read-file-objects filename state)))
      (true-listp (mv-nth 0 (read-file-objects filename state))))
  :rule-classes :type-prescription)

Subtopics

Read-object-all
(read-object-all channel state) reads all remaining objects from a file.