TextIO
structureTextIO provides input/output of characters and strings. The stream operations themselves are all defined in the IMPERATIVE_IO signature.
The openIn and openOut functions allow creation of text streams. Certain operating systems may provide other ways to open files in operating-system-specific structures.
The signature given below for TEXT_IO
is not valid SML, in that the substructure StreamIO
is respecified. (It is initially specified as a substructure having signature STREAM_IO
in the included signature IMPERATIVE_IO
having signature.) This abuse of notation seems acceptable in that the intended meaning is clear (a structure matching TEXT_IO
also matches IMPERATIVE_IO
and has a substructure StreamIO
that matches TEXT_STREAM_IO
) while avoiding a textual inclusion of the whole IMPERATIVE_IO
signature except its StreamIO
substructure.
Question:
Need note describing newline translation.
signature TEXT_IO
structure TextIO
: TEXT_IO
include IMPERATIVE_IO
structure StreamIO : TEXT_STREAM_IO
val inputLine : instream -> string
val outputSubstr : (outstream * substring) -> unit
val openIn : string -> instream
val openOut : string -> outstream
val openAppend : string -> outstream
val openString : string -> instream
val stdIn : instream
val stdOut : outstream
val stdErr : outstream
val print : string -> unit
include IMPERATIVE_IO
structure StreamIO
inputLine strm
outputSubstr (strm, ss)
output (strm, Substring.string ss)
openIn name
openOut name
openAppend name
Beyond having the initial file position be at the end of the file, any additional properities are system and implementation dependent. On operating systems (e.g., Unix) that support ``atomic append mode,'' each (flushed) output operation to the file will be appended to the end, even if there are other processes writing to the file simultaneously. However, due to buffering, these writes need not be atomic, i.e., output from a different process may interleave the output of a single write using the stream library.
openString s
val stdIn
val stdOut
val stdErr
Question:
Should these also be defined at the TEXT_STREAM_IO level?
print s
(output (stdOut, s); flushOut stdOut)
When opening a stream for writing, the stream will be block buffered by default, unless the underlying file is associated with an interactive or terminal device (i.e., the kind of the underlying iodesc
is OS.IO.Kind.tty
), in which case the stream will be line buffered. Similarly, stdOut will be line buffered in the interactive case, but may be block buffered otherwise. stdErr is initially unbuffered.
STREAM_IO, TEXT_STREAM_IO, IMPERATIVE_IO, TextPrimIO, OS.Path
Last Modified January 21, 1997
Copyright © 1996 AT&T