Next: , Previous: , Up: ref-mod   [Contents][Index]


4.11.6 Visibility Rules

By default, predicates defined in one module cannot be called from another module. This section enumerates the exceptions to this—the ways in which a predicate can be visible to modules other than the one in which it is defined.

  1. The built-in predicates can be called from any module.
  2. Any predicate that is named in the PublicPredList of a module, and that is imported by some other module M, can be called from within M.
  3. Module Prefixing: Any predicate, whether public or not, can be called from any other module if its module is explicitly given as a prefix to the goal, attached with the :/2 operator. The module prefix overrides the default module. For example,
    :- mod:foo(X,Y).
    

    always calls foo/2 in module mod. This is effectively a loophole in the module system, which allows you to override the normal module visibility rules. It is intended primarily to facilitate program development and debugging, and it should not be used extensively since it subverts the original purposes of using the module system.

    Note that a predicate called in this way does not necessarily have to be defined in the specified module. It may be imported into it. It can even be a built-in predicate, and this is sometimes useful—see ref-mod-som for an example.


Send feedback on this subject.