In addition to the standard reading procedures, MzScheme provides read-line, read-string, read-string-avail!, and read-string-avail!/enable-break:
Characters are read from input-port until a line separator or an end-of-file is read. The line separator is not included in the result string (but it is removed from the port's stream). If no characters are read before an end-of-file is encountered, eof is returned.
The mode-symbol argument determines the line separator(s). It must be one of the following symbols:
If k is 0, then the empty string is returned. Otherwise, if fewer than k characters are available before an end-of-file is encountered, then the returned string will contain only those characters before the end-of-file (i.e., the returned string's length will be less than k). If no characters are available before an end-of-file, then eof is returned.
If an error occurs during reading, some characters may be lost (i.e., if read-string successfully reads some characters before eoncountering an error, the characters are dropped.)
If the difference between start-k and end-k is 0, then 0 is returned and the string is not modified. If no characters are available before an end-of-file, then eof is returned. Otherwise, the return value is the number of characters read. If m characters are read and m < end-k - start-k, then string is not modified at indices start-k + m though end-k.
Unlike read-string, read-string-avail! returns without blocking after reading immediately-available characters. It blocks only if no characters are yet available. Also unlike read-string, read-string-avail! never drops characters; if read-string-avail! successfully reads some characters and then encounters an error, it suppresses the error (treating it roughly like an end-of-file) and returns the read characters. (The error will be triggered by future reads.) If an error is encountered before any characters have been read, an exception is raised.
If input-port is a user port, then at most one character is read. This convention allows read-string-avail! to preserve its guarantees in the presence of exceptions raised by the user port's character-reading procedure.
In addition to the standard printing procedures, MzScheme provides print, which outputs values to a port by calling the port's print handler (see section 11.1.9), write-string-avail, and write-string-avail/enable-break:
The print procedure is used to print Scheme values in a context where a programmer expects to see a Scheme value. The rationale for providing print is that display and write both have standard output conventions, and this standardization restricts the ways that an environment can change the behavior of these procedures. No output conventions should be assumed for print so that environments are free to modify the actual output generated by print in any way. Unlike the port display and write handlers, a global port print handler can be installed through the global-port-print-handler parameter (see section 9.4.1.2).
The result is the number of characters written and flushed to output-port. The write-string-avail procedure returns without blocking after writing as many characters as it can immediately flush. It blocks only if no characters can be flushed immediately.
The write-string-avail procedure never drops characters; if write-string-avail successfully writes some characters and then encounters an error, it suppresses the error and returns the number of written characters. (The error will be triggered by future writes.) If an error is encountered before any characters have been written, an exception is raised.
Formatted output is written to a port with fprintf:
The return value is void.
When an illegal format string is supplied to one of these procedures, the exn:application:type exception is raised. When the format string requires more additional arguments than are supplied, the exn:application:fprintf:mismatch exception is raised. When more additional arguments are supplied than are used by the format string, the exn:application:mismatch exception is raised.
For example,
(fprintf port "~a as a string is ~s.~n" '(3 4) "(3 4)")
prints this message to port:
(3 4) as a string is "(3 4)".
followed by a newline.