The test predicate ground/1 checks whether the given term is
ground. This means that no un-instantiated variable occurs in the
term. The predicate term_variables/2 allows collecting the
un-instantiated variables that occur in a term. The predicate will
thus return an empty list if the term was ground. Finally the
predicate sys_term_singletons/2 collects the un-instantiated
variables that only occur once. They are a subset of all the
variables that occur in the term.
K = p(X,Y)
L = [Y]
Further there are predicates to deal with existential quantifiers. The existential quantifier is represented by the (^)/2 operator. In a goal X1^..^Xn^K we call K the kernel of the goal and the variables K subtracted by the variables of X1,..,Xn the global variables of the goal. The predicates sys_goal_kernel/2 and sys_goal_globals/2 cater for the determination of the kernel and the global variables of a goal.
An alternative to using the ‘$VAR’(<number>) construct is
dynamically creating a variable names map. This has the advantage
that the construct itself can be written out. The predicate
sys_number_variables/4 helps in creating a variable names map. The
resulting variable names map can be used with the predicates
The variable names map from the current top-level query can be retrieved via the predicate sys_get_variable_names/1. The predicate will skip non-variable and duplicate entries. In the case of duplicates the entry with a lower dereferencing count is preferred. The result is intended to be used with the predicates write_term/[2,3]. If the unprocessed variable names are required the predicate sys_get_raw_variables/1 can be used.
The following term variable predicates are provided: