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