[ Predicate Database and Compiler | Reference Manual | Alphabetic Index ]

expand_clause(+Term, -TransTerm)

Apply clause transformation to Term
Term
A clause term.
TransTerm
A variable or term.

Description

Applies a clause-transformation (clause macro) to Term, if any is visible in the context module (see macro/3). If no transformation is visible, TransTerm is identical to Term.

Normally, clause expansion is performed implicitly by the compiler. For certain meta-programming applications (e.g. for writing other compilers) it can be performed explicitly using expand_clause/2. Clause expansion is the second transformation which is applied during the compilation process: macro expansion, then clause expansion, then goal inlining expansion.

Note that the result of clause transformation can be either a single clause or a list of clauses. Transformed clauses should all be standard clauses, i.e. either facts or rules with toplevel functor :-/2.

Modes and Determinism

Modules

This predicate is sensitive to its module context (tool predicate, see @/2).

Examples

    % A grammar rule is an example of a predefined clause transformation:
    ?- expand_clause((p --> q, [tok]), C).

    C = p(_263, _258) :- q(_263, _278), 'C'(_278, tok, _258)
    yes.

See Also

macro / 3, expand_goal / 2, library(source_processor)