5.5 Module Name Expansion

Some predicates take goals as arguments (i.e. meta-predicates). These arguments must include a module specification stating which module the goal refers. Some other predicates also need module information i.e. compile/1. The property of needing module information is declared with a meta-predicate declaration (see Meta Decl). Goals for these predicates are module name expanded to ensure the module information. Goals appearing in queries and meta-calls are expanded prior to execution while goals in the bodies of clauses and directives are expanded at compile time. The expansion is made by preceding the relevant argument with `Module:'. If the goal is prefixed by `Module:', Module is used for the expansion; otherwise, the source/type-in module is used. An argument is not expanded if:

Some examples:

     | ?- [user].
     | :- meta_predicate p(:), q(:).
     | r(X) :- p(X).
     | q(X) :- p(X).
     | ^D
     % consulted user in module user, 0 msec 424 bytes
     | ?- listing.
     r(A) :-
     q(A) :-

Here, p/1 and q/1 are declared as meta-predicates while r/1 is not. Thus the clause r(X) :- p(X) will be transformed to r(X) :- p(M:X), by item 2 above, where M is the type-in module, whereas q(X) :- p(X) will not.

     | ?- m:assert(f(1)).

Here, assert/1 is called in the module m. However, this does not ensure that f(1) is asserted into m. The fact that assert/1 is a meta-predicate makes the system module name expand the goal, transforming it to m:assert(m:f(1)) before execution. This way, assert/1 is supplied the correct module information.