read_term/[2,3] [ISO]read_term(-Term, +Options)
read_term(+Stream, -Term, +Options)
Read a term from Stream, optionally returning extra information about the term.
A valid Prolog input stream, defaults to the current input stream.
The term that is read.
A list of zero or more of the following:
syntax_errors(Val)syntax_errors Prolog flag. The
default is set by that flag. See ref-lps-flg.
variables(Vars)variable_names(Names)=Var
pairs, where each Name is an atom indicating the name of a
non-anonymous variable in the term, and Var is the
corresponding variable.
singletons(Names)=Var
pairs, one for each variable appearing only once in the term
and whose name does not begin with ‘_’.
The Prolog flag legacy_char_classification changes the criteria
for which variables are included in Names. When
legacy_char_classification is in effect the list also includes
variables that occur only once in the term and whose name begin with
‘_’ followed by a character that is not an uppercase Latin 1
character.
cycles(Boolean)true or false. If selected, any
occurrences of @/2 in the term read in are replaced by the
potentially cyclic terms they denote as described above.
Otherwise (the default), Term is just unified with the
term read in.
layout(Layout)consume_layout(Boolean)true or false. If this option is
true, read_term/[2,3] will consume the
layout-text-item that follows the terminating ‘.’ (this
layout-text-item can either be a layout-char or a
comment starting with a ‘%’). If the option is false, the
layout-text-item will remain in the input stream, so that
subsequent character input predicates will see it. The default of
the consume_layout option is false.
The characters read are subject to character-conversion.
Stream errors (see ref-iou-sfh-est), plus:
syntax_errorinstantiation_errortype_errordomain_error | ?- read_term(T, [variable_names(L)]).
|: append([U|X],Y,[U|Z]) :- append(X,Y,Z).
L = ['U'=_A,'X'=_B,'Y'=_C,'Z'=_D],
T = (append([_A|_B],_C,[_A|_D]):-append(_B,_C,_D))
| ?- read_term(T, [layout(L), variable_names(Va), singletons(S)]).
|: [
foo(X),
X = Y
].
L = [35,[36,36],[36,[37,37,37],38]],
S = ['Y'=_A],
T = [foo(_B),_B=_A],
Va = ['X'=_B,'Y'=_A]
| ?- read_term(T, [consume_layout(false)]), get_code(C).
|: 1.
C = 10,
T = 1
| ?- read_term(T, [consume_layout(true)]), get_code(C).
|: 1.
|: a
C = 97,
T = 1
read/[1,2], char_conversion/2, ref-iou-tin-trm, ref-lps-flg.