[ Modules | Reference Manual | Alphabetic Index ]

lock

Locks access to internals of the current module

Description

Used to forbid access from outside the current module to its internals, except through the module interface (i.e. its exports).

This primitive is usually used a directive in the source code of the module to be locked.

A module locked with lock/0 cannot be unlocked. Repeated locking (from within the module) is silently accepted.

Modes and Determinism

Modules

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

Examples

    % After compiling the following code:
     :- module(m).
     :- export pub/0.
     pub :- writeln(pub).
     priv :- writeln(priv).
     :- lock.


    ?- module(m).
    trying to access a locked module in module(m)

    ?- call(pub) @ m.
    pub
    yes.

    ?- call(priv) @ m.
    trying to access a locked module in priv

    ?- assert(foo) @ m.
    trying to access a locked module in assert_(foo, m)

See Also

lock_pass / 1, unlock / 2, get_module_info / 3