• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Community
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
        • Crypto-hdwallet
        • Apt
        • Error-checking
        • Fty-extensions
        • Isar
        • Kestrel-utilities
        • Set
        • C
        • Soft
        • Bv
        • Imp-language
        • Ethereum
        • Event-macros
        • Java
        • Riscv
        • Bitcoin
        • Zcash
        • Yul
        • ACL2-programming-language
        • Prime-fields
        • Json
        • Syntheto
        • File-io-light
          • Read-file-into-byte-array-stobj
          • Read-file-into-character-array-stobj
          • Read-objects-from-book
          • Write-strings-to-file!
          • Write-strings-to-file
          • Write-objects-to-file!
          • Write-bytes-to-file!
          • Write-objects-to-file
          • Read-objects-from-file
          • Read-object-from-file
            • Read-file-into-byte-list
            • Write-strings-to-channel
            • Write-bytes-to-file
            • Write-bytes-to-channel
            • Read-file-into-character-list
          • Cryptography
          • Number-theory
          • Axe
          • Lists-light
          • Builtins
          • Solidity
          • Helpers
          • Htclient
          • Typed-lists-light
          • Arithmetic-light
        • X86isa
        • Axe
        • Execloader
      • Math
      • Testing-utilities
    • Io
    • File-io-light

    Read-object-from-file

    Read an ACL2 object from a file.

    ;; Returns (mv erp object state) where either ERP is non-nil (meaning an error
    ;; occurred) or else OBJECT is the first ACL2 object in the file.
    ;; TODO: Add option to set the package of the symbols read in? (See read-objects-from-file-with-pkg).
    (defund read-object-from-file (filename state)
      (declare (xargs :guard (stringp filename)
                      :stobjs state))
      (mv-let (channel state)
        (open-input-channel filename :object state)
        (if (not channel)
            ;; Error:
            (mv `(:could-not-open-channel ,filename) nil state)
          (mv-let (eof maybe-object state)
            (read-object channel state)
            (let ((state (close-input-channel channel state)))
              (if eof
                  ;; Error (no objects in file):
                  (mv `(:end-of-file ,filename) nil state)
                (mv nil ; no error
                    maybe-object
                    state)))))))