11.3.182 read/[1,2] [ISO]



read(+Stream, -Term)

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

read_term(Term, [])

read_term(Stream, Term, [])


stream_object, must be ground

A valid Prolog input stream.


The term to be read.


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.

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.


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

A syntax error was found.


See Also

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

Send feedback on this subject.