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-file
open ports for the given filenames. They each return two values: the newly open port and anerrors
enumerand status. Users of these procedures should always check the error status before proceeding to operate with the port.Close-input-port
&close-output-port
close their port arguments and return theerrors
enumerand status of the closing.
Read-char
reads & consumes a single character from its input-port argument.Peek-char
reads, but does not consume, a single character from input-port.Read-integer
parses an integer literal, including sign. All of these also return two other values: whether or not the file is at the end and anyerrors
enumerand 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-char
writes individual characters.Newline
writes newlines (line-feed, or ASCII codepoint 10, on Unix).Write-string
writes the contents of string.Write-integer
writes an ASCII representation of integer to port, suitable to be read byread-integer
. These all return anerrors
enumerand 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.