read(+Stream, -Term)

Reads the next term from the current input stream or Stream and unifies it with Term.


Stream stream_object
a valid Prolog stream, which is open for input
Term term
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.

For the syntax of Prolog terms see ref-syn-syn.

The term is read with respect to current operator declarations. See ref-syn-ops, for a discussion of operators.

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.

When a syntax error is encountered, an error message is printed and then read/1 tries again, starting immediately after the full-stop that terminated the erroneous "term". That is, read/1 does not fail on a syntax error, but perseveres until it eventually manages to read a term.

If the end of the current input stream has been reached, then read(X) will cause X to be unified with the atom end_of_file


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


See Also

read_term/[2,3], prompt/[2,3] ref-syn-syn