Next: Pre-Scheme access to C functions and macros, Previous: Pre-Scheme error handling, Up: Standard Pre-Scheme environment
Pre-Scheme's I/O facilities are somewhat different from Scheme's, given
the low level and the static type strictness. There is no exception
mechanism in Pre-Scheme; everything is maintained by returning a status
token, as in C. Pre-Scheme's built-in I/O facilities are buffered.
1
(see Low-level Pre-Scheme memory manipulation, for two other I/O
primitives, read-block & write-block, for reading &
writing blocks of direct memory.)
Open-input-file&open-output-fileopen ports for the given filenames. They each return two values: the newly open port and anerrorsenumerand status. Users of these procedures should always check the error status before proceeding to operate with the port.Close-input-port&close-output-portclose their port arguments and return theerrorsenumerand status of the closing.
Read-charreads & consumes a single character from its input-port argument.Peek-charreads, but does not consume, a single character from input-port.Read-integerparses an integer literal, including sign. All of these also return two other values: whether or not the file is at the end and anyerrorsenumerand status. If any error occurred, the first two values returned should be ignored. If status is(enum errors no-errors), users of these three procedures should then check eof?; it is true if input-port was at the end of the file with nothing more left to read and false otherwise. Finally, if both status is(enum errors no-errors)and eof? is false, the first value returned may be safely used.
These all write particular elements to their output-port arguments.
Write-charwrites individual characters.Newlinewrites newlines (line-feed, or ASCII codepoint 10, on Unix).Write-stringwrites the contents of string.Write-integerwrites an ASCII representation of integer to port, suitable to be read byread-integer. These all return anerrorsenumerand status. If it isno-errors, the write succeeded.
Forces all buffered output in output-port. Status tells whether or not the operation was successful.
[1] Scheme48's VM does not use Pre-Scheme's built-in I/O
facilities to implement channels — it builds its
own lower-level facilities that are still OS-independent, but, because
they're written individually for different OSs, they integrate better
as low-level I/O channels with the OS. On Unix, the Scheme48 VM uses
file descriptors; Pre-Scheme's built-in I/O uses stdio.
Scheme48's VM uses Pre-Scheme's built-in I/O only to read heap images.