If port is omitted from any input procedure, it defaults to the
value returned by (current-input-port). It is an error to attempt
an input operation on a closed port.
(read) ¶(read port) ¶The read procedure converts external representations of Scheme
objects into the objects themselves. That is, it is a parser for the
non-terminal ⟨datum⟩ (see External representations;
see Pairs and lists). It returns the next object parsable from the
given textual input port, updating port to point to the
first character past the end of the external representation of the
object.
Implementations may support extended syntax to represent record types or other types that do not have datum representations.
If an end of file is encountered in the input before any characters are
found that can begin an object, then an end-of-file object is returned.
The port remains open, and further attempts to read will also return an
end-of-file object. If an end of file is encountered after the
beginning of an object’s external representation, but the external
representation is incomplete and therefore not parsable, an error that
satisfies read-error? is signaled.
(read-char) ¶(read-char port) ¶Returns the next character available from the textual input port, updating the port to point to the following character. If no more characters are available, an end-of-file object is returned.
(peek-char) ¶(peek-char port) ¶Returns the next character available from the textual input port, but without updating the port to point to the following character. If no more characters are available, an end-of-file object is returned.
Note: The value returned by a call to
peek-charis the same as the value that would have been returned by a call toread-charwith the same port. The only difference is that the very next call toread-charorpeek-charon that port will return the value returned by the preceding call topeek-char. In particular, a call topeek-charon an interactive port will hang waiting for input whenever a call toread-charwould have hung.
(read-line) ¶(read-line port) ¶Returns the next line of text available from the textual input port, updating the port to point to the following character. If an end of line is read, a string containing all of the text up to (but not including) the end of line is returned, and the port is updated to point just past the end of line. If an end of file is encountered before any end of line is read, but some characters have been read, a string containing those characters is returned. If an end of file is encountered before any characters are read, an end-of-file object is returned. For the purpose of this procedure, an end of line consists of either a linefeed character, a carriage return character, or a sequence of a carriage return character followed by a linefeed character. Implementations may also recognize other end of line characters or sequences.
(eof-object? obj) ¶Returns #t if obj is an end-of-file object, otherwise
returns #f. The precise set of end-of-file objects will vary
among implementations, but in any case no end-of-file object will ever
be an object that can be read in using read.
(eof-object) ¶Returns an end-of-file object, not necessarily unique.
(char-ready?) ¶(char-ready? port) ¶Returns #t if a character is ready on the textual input
port and returns #f otherwise. If char-ready
returns #t then the next read-char operation on the given
port is guaranteed not to hang. If the port is at end of
file then char-ready? returns #t.
Rationale: The
char-ready?procedure exists to make it possible for a program to accept characters from interactive ports without getting stuck waiting for input. Any input editors associated with such ports must ensure that characters whose existence has been asserted bychar-ready?cannot be removed from the input. Ifchar-ready?were to return#fat end of file, a port at end of file would be indistinguishable from an interactive port that has no ready characters.
(read-string k) ¶(read-string k port) ¶Reads the next k characters, or as many as are available before the end of file, from the textual input port into a newly allocated string in left-to-right order and returns the string. If no characters are available before the end of file, an end-of-file object is returned.
(read-u8) ¶(read-u8 port) ¶Returns the next byte available from the binary input port, updating the port to point to the following byte. If no more bytes are available, an end-of-file object is returned.
(peek-u8) ¶(peek-u8 port) ¶Returns the next byte available from the binary input port, but without updating the port to point to the following byte. If no more bytes are available, an end-of-file object is returned.
(u8-ready?) ¶(u8-ready? port) ¶Returns #t if a byte is ready on the binary input port and
returns #f otherwise. If u8-ready? returns
#t then the next read-u8 operation on the given port
is guaranteed not to hang. If the port is at end of file then
u8-ready? returns #t.
(read-bytevector k) ¶(read-bytevector k port) ¶Reads the next k bytes, or as many as are available before the end of file, from the binary input port into a newly allocated bytevector in left-to-right order and returns the bytevector. If no bytes are available before the end of file, an end-of-file object is returned.
(read-bytevector! bytevector) ¶(read-bytevector! bytevector port) ¶(read-bytevector! bytevector port start) ¶(read-bytevector! bytevector port start end) ¶Reads the next end − start bytes, or as many as are available before the end of file, from the binary input port into bytevector in left-to-right order beginning at the start position. If end is not supplied, reads until the end of bytevector has been reached. If start is not supplied, reads beginning at position 0. Returns the number of bytes read. If no bytes are available, an end-of-file object is returned.