get-char, read-char - read a character from a textual input port

LIBRARY

(import (rnrs))                     ;R6RS
(import (rnrs io ports))            ;R6RS
(import (rnrs io simple))           ;R6RS, read-char
(import (scheme r5rs))              ;R7RS
(import (scheme base))              ;R7RS

SYNOPSIS

(get-char textual-input-port)       ;R6RS only
(read-char)
(read-char textual-input-port)

DESCRIPTION

Reads from textual-input-port, blocking as necessary until a character is available from textual-input-port, or the data that are available cannot be the prefix of any valid encoding, or an end of file is reached.

If a complete character is available before the next end of file, that character is returned, and the input port is updated to point past that character. If an end of file is reached before any data are read, the end-of-file object is returned.

If textual-input-port is omitted, it defaults to the value returned by current-input-port(3scm)

RETURN VALUES

Returns a single value; a character or an end-of-file object.
R6RS
There is a single, unique end-of-file object.

EXAMPLES

(let lp ()
  (let ((c (read-char)))
    (unless (eof-object? c)
      (write-char (char-upcase c))
      (lp))))

COMPATIBILITY

Except for differences in the supported character set and in how errors are handled, this procedure works the same everywhere.

ERRORS

This procedure can raise exceptions with the following condition types:
&assertion (R6RS)
The wrong number of arguments was passed or an argument was outside its domain.
&i/o-decoding (R6RS)
The port's transcoder is in raise mode and it encountered an invalid byte sequence.
&i/o-read (R6RS)
There was an I/O error during the read operation.
&i/o-port (R6RS)
This condition specifies the port object related to an &i/o-read condition.
R7RS
The assertions described above are errors. Implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically.

SEE ALSO

put-char(3scm), get-line(3scm), lookahead-char(3scm)

STANDARDS

R4RS, IEEE Scheme, R5RS, R6RS, R7RS

HISTORY

The name get-char is new for the reworked I/O in R6RS. The read-char procedure first appeared in R2RS. Scheme prior to this, running on MacLISP, had the readch function. LISP 1.5 had the subroutines startread, advance, and endread for reading characters from punched cards.

AUTHORS

This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://github.com/schemedoc/manpages/.


Markup created by unroff 1.0sc,    March 04, 2023.