The “Read” predicates are
read(
-Term)
read(
+Stream,
-Term)
read_term(
-Term,
+Options)
read_term(
+Stream,
-Term,
+Options)
read_term/[2,3]
offers many options to return extra information about the
term.
When Prolog reads a term from the current input stream the following conditions must hold:
read/[1,2]
does not terminate 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.
term
. That is, it does not fail on a syntax error,
but perseveres until it eventually manages to read a term. This behavior
can be changed with prolog_flag/3
or using read_term/[2,3]
.
read(
X)
will cause X to be unified with the atom
end_of_file
.