• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Debugging
    • Projects
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
      • Io
        • Fmt
        • Msg
        • Cw
        • Set-evisc-tuple
        • Set-iprint
        • Print-control
        • Read-file-into-string
        • Msgp
        • Std/io
        • Printing-to-strings
        • Evisc-tuple
        • Output-controls
        • Observation
        • *standard-co*
        • Standard-oi
        • Ppr-special-syms
        • Standard-co
        • Without-evisc
        • Serialize
        • Output-to-file
        • Fmt-to-comment-window
        • Princ$
        • Character-encoding
        • Open-output-channel!
        • Cw-print-base-radix
        • Set-print-case
        • Set-print-base
        • Print-object$
        • Fmx-cw
        • Extend-pathname
        • Print-object$+
        • Set-print-radix
        • Set-fmt-hard-right-margin
        • File-write-date$
        • Proofs-co
        • Set-print-base-radix
        • *standard-oi*
        • Print-base-p
        • Wof
        • File-length$
        • Fms!-lst
        • Delete-file$
        • *standard-ci*
        • Write-list
        • Fmt!
        • Fms
        • Cw!
        • Fmt-to-comment-window!
        • Fms!
        • Eviscerate-hide-terms
        • Fmt1!
        • Fmt-to-comment-window!+
        • Read-file-into-byte-array-stobj
        • Fmt1
        • Fmt-to-comment-window+
        • Cw-print-base-radix!
        • Read-file-into-character-array-stobj
        • Cw!+
        • Write-objects-to-file!
        • Read-objects-from-book
          • Newline
          • Fmx
          • Cw+
          • Probe-file
          • Write-objects-to-file
          • Read-objects-from-file
          • Read-object-from-file
          • Read-file-into-byte-list
          • Set-fmt-soft-right-margin
          • Read-file-into-character-list
          • Io-utilities
        • Defttag
        • Sys-call
        • Save-exec
        • Quicklisp
        • Oslib
        • Std/io
        • Bridge
        • Clex
        • Tshell
        • Unsound-eval
        • Hacker
        • Startup-banner
        • Command-line
      • Hardware-verification
      • Software-verification
      • Math
      • Testing-utilities
    • Io
    • File-io-light

    Read-objects-from-book

    Read the forms in a book.

    ;; Read forms from FILENAME but require the first form to be an IN-PACKAGE form
    ;; used for interpreting symbols in the rest of the forms.  Returns (mv erp
    ;; forms state).  Consider first calling something like load-port-file-if-exists
    ;; to ensure the packages are known.
    (defund read-objects-from-book (filename state)
      (declare (xargs :guard (stringp filename) ; includes the .lisp extension
                      :mode :program            ; because of in-package-fn
                      :stobjs state))
      ;; First read just the in-package form:
      (mv-let (erp first-form state)
        (read-object-from-file filename state)
        (if erp
            (mv erp nil state)
          (if (not (and (consp first-form)
                        (eq 'in-package (car first-form))))
              (prog2$ (er hard? 'read-objects-from-book "ERROR: Expected an in-package form but got ~x0." first-form)
                      (mv :missing-in-package nil state))
            (let ((book-package (cadr first-form)))
              ;; Read the book contents after temporarily setting the package to book-package:
              (mv-let (erp forms state)
                (read-objects-from-file-with-pkg filename book-package state)
                (if erp ; error reading forms
                    (mv erp nil state)
                  ;; No error:
                  (mv nil forms state))))))))