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

expand_clause(+Term, -TransTerm)

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


Applies a clause-transformation (clause macro) to Term, if any is visible in the caller 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


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


    % 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)

See Also

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