This is a generalisation of the predicates read/2 and readvar/3. Options is a (possibly empty) list of the following options:
returns a duplicate-free list of all the variables in the term that has been read (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 the term that has been read, 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 the term that has been read, 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)