Node:Def Modules, Next:, Previous:Module Spec, Up:Module Intro



Defining Modules

A module is normally defined by putting a module declaration in a source file. A module declaration has the form:

:- module(ModuleName, ExportList[, Options]).

where ModuleName is an atom, and should precede all other clauses and directives of that file.

When the file is loaded, all predicates in the file go into ModuleName and the predicates of the ExportList are exported. When a module declaration is processed, all existing predicates in the module are erased before the new ones are loaded. A file which contains a module declaration is henceforth called a module-file.

Options is an optional argument, and should be a list. The only available option is hidden(Boolean), where Boolean is false (the default) or true. In the latter case, tracing of the predicates of the module is disabled (although spypoints can be set), and no source information is generated at compile time.

A module can also be defined dynamically by asserting or loading predicates to it:

| ?- assert(m:p(x)).

creates the module m, if it does not already exists, and asserts p(x) to it.

| ?- compile(m:f).

creates the module m and loads f into m.

Dynamically created modules have no public predicates.