[ Term Manipulation | Reference Manual | Alphabetic Index ]

term_variables_count(?Term, -N)

Succeeds if N is the number of distinct variables in Term.
Prolog term.
Variable or integer.


This predicate counts the number of different variables in Term. Repeat occurrences of variables are ignored.

As usual, attributed variables are also considered variables.

This predicate can handle cyclic terms.

Modes and Determinism


    term_variables_count(f(bar), N)       gives N=0
    term_variables_count(f(X,b,Y), N)     gives N=2
    term_variables_count(f(X,Y,X), N)     gives N=2
    term_variables_count(X, N)            gives N=1
    X=f(X), term_variables_count(X, N)    gives N=0
    X=f(X,Y), term_variables_count(X, N)  gives N=1

See Also

term_variables / 2, term_variables_array / 2, nonground / 1, nonground / 2, nonground / 3, nonvar / 1, var / 1