[ Control | Reference Manual | Alphabetic Index ]

Goal @ ContextModule

Goal is executed in the calling context of ContextModule.
Goal
Callable term (atom or compound).
ContextModule
Atom.

Description

The calling context of a goal is normally the module where the goal is called. @/2 allows to specify this context module explicitly. This is needed when writing meta-predicates (i.e. predicates which have goals or predicates as their arguments) or predicates which depend otherwise on the module system's visibility rules.

@/2 changes only the context module, not the lookup module. I.e. the way the definition of Goal is found is not affected at all. To specify the lookup module, use :/2. The following table summarises:

	Call within module(m)         lookup module    caller module

	..., twice(X), ...               m               m
	..., lm : twice(X), ...         lm               m
	..., twice(X) @ cm, ...          m              cm
	..., lm : twice(X) @ cm, ...    lm              cm
	..., call(twice(X)) @ cm, ...   cm              cm
If Goal is not a tool-predicate, then Goal@ContextModule is completely equivalent to Goal.

Modules

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

Fail Conditions

Fails if Goal fails

Resatisfiable

Resatisfiable if Goal is resatisfiable

Exceptions

(4) instantiation fault
Goal is not instantiated.
(5) type error
Goal is neither an atom nor a compound term.
(68) calling an undefined procedure
Goal is an undefined procedure in the caller module.

Examples

    [eclipse 1]: [user].
     :- tool(where/0, where/1).
     where(Module) :-
        printf("where/0 was called from module %w\n", [Module]).
    ^D
    [eclipse 2]: where.
    where/0 was called from module eclipse
    yes.
    [eclipse 3]: where @ m.
    where/0 was called from module m
    yes.
    [eclipse 4]: call(where) @ m.
    calling an undefined procedure where in module m

    [eclipse 1]: [user].
     :- tool(print_local_preds/0, print_local_preds/1).
     print_local_preds(Module) :-
            current_predicate(P) @ Module,
            get_flag(P, visibility, local) @ Module,
            writeln(P),
            fail.
    ^D
    [eclipse 2]: print_local_preds.
    print_local_preds / 0
    print_local_preds / 1



See Also

: / 2, call / 1, tool / 2