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.