This section describes the standard operations on textual input ports. Following that, some useful custom operations are described.
Removes the next character available from port and returns it.
If port has no more characters and will never have any (e.g.
at the end of an input file), this operation returns an end-of-file
object. If port has no more characters but will eventually have
some more (e.g. a terminal where nothing has been typed recently),
and it is in non-blocking mode,
#f is returned; otherwise the
operation hangs until input is available.
Reads the next character available from port and returns it.
The character is not removed from port, and a subsequent
attempt to read from the port will get that character again. In other
respects this operation behaves like
#t if at least one character is
available to be read from port. If no characters are available,
the operation waits up to k milliseconds before returning
#f, returning immediately if any characters become available
while it is waiting.
These operations are like
read-char, except that they read or
discard multiple characters at once. All characters up to, but
excluding, the first character in char-set (or end of file) are
read from port.
read-string returns these characters as
a newly allocated string, while
discard-chars discards them and
returns an unspecified value. These operations hang until sufficient
input is available, even if port is in non-blocking mode. If
end of file is encountered before any input characters,
read-string returns an end-of-file object.
Reads characters from port into the substring defined by string, start, and end until either the substring has been filled or there are no more characters available. Returns the number of characters written to the substring.
If port is an interactive port, and at least one character is
immediately available, the available characters are written to the
substring and this operation returns immediately. If no characters
are available, and port is in blocking mode, the operation
blocks until at least one character is available. Otherwise, the
This is an extremely fast way to read characters from a port.
Each of these procedures invokes the respective operation on textual-input-port. For example, the following are equivalent:
(input-port/read-char textual-input-port) ((textual-port-operation textual-input-port 'read-char) textual-input-port)
The following custom operations are implemented for input ports to files, and will also work with some other kinds of input ports:
#t if port is known to be at end of file,
otherwise it returns
Returns an estimate of the number of characters remaining to be read
from port. This is useful only when
port is a file port in binary mode; in other
cases, it returns
Returns the number of unread characters that are stored in port’s buffer. This will always be less than or equal to the buffer’s size.
Returns the maximum number of characters that port’s buffer can hold.
Resizes port’s buffer so that it can hold at most size characters. Characters in the buffer are discarded. Size must be an exact non-negative integer.