11.3.181 read/[1,2] [ISO]

Synopsis

read(-Term)

read(+Stream, -Term)

Reads the next term from Stream and unifies it with Term. Same as:

read_term(Term, [])

read_term(Stream, Term, [])

Arguments

Stream
stream_object, must be ground

A valid Prolog input stream.

Term
term

The term to be read.

Description

Term must be followed by a full-stop. The full-stop is removed from the input stream and is not a part of the term that is read. The term is read with respect to current operator declarations.

Does not finish until the full-stop is encountered. Thus, if you type at top level

     | ?- read(X)

you will keep getting prompts (first ‘|: ’, and five spaces thereafter) every time you type <RET>, but nothing else will happen, whatever you type, until you type a full-stop.

If a syntax error is encountered, the action taken depends on the current value of the syntax_errors Prolog flag. See ref-lps-flg.

If the end of the current input stream has been reached, then Term will be unified with the atom end_of_file. Further calls to read/[1,2] for the same stream will then raise an exception, unless the stream is connected to the terminal. The characters read are subject to character-conversion.

Exceptions

Stream errors (see ref-iou-sfh-est), plus:

syntax_error
A syntax error was found.

Examples

See Also

read_term/[2,3], char_conversion/2, ref-iou-tin-trm.


Send feedback on this subject.