HELP EXPAND_TERM                                Simon Nichols, July 1990

Term pre-processing.

    ?- expand_term(__T1, __T2).


Poplog Prolog provides a term pre-processing facility which allows each
top-level term __T1 read by the compiler to be transformed into a new term
__T2. This provides a generalisation of the grammar rule notation for
expressing definite clause grammars (see ________PLOGHELP * ____________GRAMMAR_RULE): just
as grammar rules are transformed into conventional Prolog clauses as
they are read in, it is possible to specify other transformations by
asserting additional clauses for the predicate term_expansion/2.

The Prolog compiler invokes expand_term/2 on each top-level term which
it reads. This applies both to clauses read in _______consult or _________reconsult
mode, and to goals read in _____query mode. The default transformation
translates grammar rules into ordinary Prolog clauses. But if there any
clauses for term_expansion/2, this predicate is called to transform the
clauses before the grammar rule transformation is applied. In other
words, user defined transformations are applied before system defined
ones.

The arguments to term_expansion/2 are an input term __T1 and an output
term __T2 which is the result of transforming __T1.

For example, if you were to write a runtime typechecking utility for
Prolog which required a goal of the form

    typecheck(ClauseHead)

to be inserted at the start of the body of each clause, this could be
accomplished by compiling:

    :- current_op(Prec, xfx, ':-'), op(Prec, xfx, ':--').

    term_expansion((H :-- B), (H :- typecheck(H), B)).

Any predicate definition written to use ':--' rather than ':-' would
then have the call to typecheck/1 automatically prepended to the goals
in its body.


--- ___________________________C.all/plog/help/expand_term
--- _________Copyright __________University __of ______Sussex _____1993. ___All ______rights _________reserved.
