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.
?- 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]