The built-in predicate
numbervars/3 makes a term
ground by binding the variables in it to subterms of the form
where N is an integer. Most of the calls to
numbervars/3 look like
numbervars(Term, 0, _)
which can be abbreviated to
if you use this package.
varnumbers/3 is a partial inverse to
varnumbers(Term, N0, Copy)
unifies Copy with a copy of Term in which subterms of the form
) where N is an integer not less than N0 (that is, subterms
which might have been introduced by
numbervars/3 with second argument
N0) have been consistently replaced by new variables. Since 0 is the
usual second argument of
numbervars/3, there is also
This provides a facility whereby a Prolog-like data base can be
kept as a term. For example, we might represent
Clauses = [ (append(, '$VAR'(0), '$VAR'(0)) :- true), (append(['$VAR'(0)|'$VAR'(1), '$VAR'(2), ['$VAR'(0)|'$VAR(3)]) :- append('$VAR'(1), '$VAR'(2), '$VAR'(3))) ]
and we might access clauses from it by doing
prove(Goal, Clauses) :- member(Clause, Clauses), varnumbers(Clause, (Goal:-Body)), prove(Goal).
)with values of N ranging from 0 up.
)and Copy is a copy of Term with such subterms replaced by variables.
)(so that all subterms
>=N0) and Copy is a copy of Term with such subterms replaced by variables.