This is a generalisation of the read/2 predicate (and deprecated predicates read_annotated/2,3, readvar/3). It reads one term in ECLiPSe syntax from the input stream Stream, and returns it as Term. Options is a (possibly empty) list of the following options:
returns AnnTerm, which is a compound annotated_term{} that is structurally similar to Term and contains all information about Term, plus additional type information, variable names, and source position annotations for all subterms. For details see read_annotated/3.
returns the Stream line number where Term starts.
returns a duplicate-free list of all the variables in Term (including anonymous variables).
returns a duplicate-free list of structures of the form Name=Var, where Var is a named (non-anonymous) variable which occurs in Term, and Name is an atom, representing the source name.
returns a list of structures of the form Name=Var, where Var is a named (non-anonymous) variable which occurs only once in Term, and Name is an atom, representing the source name.
modifies the treatment of syntax errors: if 'quiet', the predicate fails quietly; if 'fail', an error message is printed and then the predicate fails; if 'error', a term of the form error(syntax_error(MessageString),context(...)) is thrown. The default is 'fail' if the per-module syntax_option 'syntax_errors_fail' is set, otherwise 'error'.
?- read_term(T, []).
foo(X,_,bar(X,Y,_Z)).
T = foo(X, _255, bar(X, Y, _Z))
?- read_term(T, [variable_names(VN)]).
foo(X,_,bar(X,Y,_Z)).
T = foo(X, _260, bar(X, Y, _Z))
VN = ['X' = X, 'Y' = Y, '_Z' = _Z]
?- read_term(T, [variables(V),variable_names(VN),singletons(S)]).
foo(X,_,bar(X,Y,_Z)).
T = foo(X, _278, bar(X, Y, _Z))
V = [X, _278, Y, _Z]
VN = ['X' = X, 'Y' = Y, '_Z' = _Z]
S = ['_Z' = _Z, 'Y' = Y]
?- read_term(T, [syntax_errors(quiet)]).
a b.
No (0.00s cpu)
?- read_term(T, [annotated(AT)]).
foo(3,X).
T = foo(3, X)
AT = annotated_term(foo(
annotated_term(3, integer, user, 1, 4, 5),
annotated_term(X, var('X'), user, 1, 6, 7)),
compound, user, 1, 0, 4)