• 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
    • Open-output-channel

    Std/io/open-output-channel

    Open a file for writing.

    Signature: (open-output-channel file-name typ state-state) returns (mv channel state)

    • file-name can be either :string (to indicate that you want to print to a string stream), or a string like "temp.txt" that names the file to write to.
    • typ is the type of input to be used and must be one of the valid *file-types*.
    • state is the ACL2 state.

    This is a logic-mode function, but its logical definition is tricky; see logical-story-of-io. The main logical consequence is that (on success) channel will become an open output channel of the indicated type, and hence can be written to or closed.

    Under the hood, we either create a new Lisp string stream in memory (when file-name is :string) or we use Lisp's file operations to open file-name for writing. Note that if file-name refers to a file that already exists, it will be overwritten (i.e., not appended to).

    On success, channel is a symbol in the ACL2-OUTPUT-CHANNEL package. Under the hood, this symbol will be associated with the Lisp stream. Note that to avoid resource leaks, you should eventually use close-output-channel to free this stream.

    On failure, channel is nil. There are various reasons that open-output-channel can fail. For example, this can happen if you try to write to a file in a directory that does not exist, and it may happen (depending on your host Lisp) if you try to open a file for which you do not have permission.

    Definitions and Theorems

    Theorem: state-p1-of-open-output-channel

    (defthm
       state-p1-of-open-output-channel
       (implies
            (and (state-p1 state)
                 (stringp fname)
                 (member type *file-types*))
            (state-p1 (mv-nth 1
                              (open-output-channel fname type state)))))

    Theorem: symbolp-of-open-output-channel

    (defthm symbolp-of-open-output-channel
            (symbolp (mv-nth 0
                             (open-output-channel fname type state)))
            :rule-classes (:rewrite :type-prescription))

    Theorem: open-output-channel-p1-of-open-output-channel

    (defthm
       open-output-channel-p1-of-open-output-channel
       (implies
            (and (state-p1 state)
                 (stringp fname)
                 (member type *file-types*)
                 (equal channel
                        (mv-nth 0
                                (open-output-channel fname type state)))
                 channel)
            (open-output-channel-p1
                 channel type
                 (mv-nth 1
                         (open-output-channel fname type state)))))

    Theorem: open-output-channel-p1-of-put-global

    (defthm
     open-output-channel-p1-of-put-global
     (equal
        (open-output-channel-p1 channel type (put-global key val state))
        (open-output-channel-p1 channel type state)))