Availability:built-in
library(backcomp). The variables in List 
are ordered in order of appearance traversing Term 
depth-first and left-to-right. See also
term_variables/3 
and nonground/2. 
For example:
?- term_variables(a(X, b(Y, X), Z), L). L = [X, Y, Z].