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

4.11.2 Basic Concepts

Each predicate in a program is identified by its module, as well as by its name and arity.

A module defines a set of predicates, among which some have the property of being public. Public predicates are predicates that can be imported by other modules, which means that they can then be called from within those modules. Predicates that are not public are private to the module in which they are defined; that is, they cannot be called from outside that module (except by explicitly overriding the modularity rules as described in ref-mod-vis).

There are two kinds of importation:

  1. A module M1 may import a specified set of predicates from another module M2. All the specified predicates should be public in M2.
  2. A module M1 may import all the public predicates of another module M2.

Built-in predicates do not need to be imported; they are automatically available from within any module.

There is a special module called user, which is used by default when predicates are being defined and no other module has been specified.

The other predefined module is the prolog module where all the built-in predicates reside. The exported built-in predicates are automatically imported into each new module as it is created.

If you are using a program written by someone else, then you need not be concerned as to whether or not that program has been made into a module. The act of loading a module from a file using compile/1, or ensure_loaded/1 (see ref-lod) will automatically import all the public predicates in that module. Thus the command

:- ensure_loaded(library(lists)).

will load the list-processing predicates from the library and make them available.

Send feedback on this subject.