[ Term Manipulation | Reference Manual | Alphabetic Index ]

# term_variables_array(?Term, -VarArr)

Succeeds if VarArr is an array containing all variables in Term.

Term
  Prolog term.
VarArr
  Array or variable.

## Description

This predicate collects all the variables inside Term into an array VarArr. Every variable occurs only once in VarArr, even if it occurs several times in Term. The order of the variables in the array corresponds to the order in which they are first encountered during a depth-first, left-to-right traversal of Term.

As usual, attributed variables are also considered variables.

This predicate can handle cyclic terms.

### Modes and Determinism

- term_variables_array(?, -) is det

## Examples

        term_variables(atom, Vs).	      % gives Vs = []
        term_variables(Term, Vs).         % gives Vs = [](Term)
        term_variables(f(a,Y,c), Vs).     % gives Vs = [](Y)
        term_variables(f(X,g(Y),c), Vs).  % gives Vs = [](X,Y)
        term_variables(X+3*Y, Vs).        % gives Vs = [](X,Y)
        term_variables([X,Y,Z], Vs).      % gives Vs = [](X,Y,Z)
        term_variables([](X,Y,Z), Vs).    % gives Vs = [](X,Y,Z)
        term_variables([X,Y,X], Vs).      % gives Vs = [](X,Y)
        term_variables(s(X{a}), Vs).      % gives Vs = [](X{a})

## See Also

term_variables / 2, nonvar / 1, var / 1