Module System

Predicates, evaluable functions and syntax operators can be protected from external access. A Prolog text member can be either public, package local or private. Private members can only be seen from within the same Prolog text. Package local members will be seen from Prolog texts that share the same package name. And public members are visible everywhere. The default visibility for a member is package local inside Prolog texts elevated to modules and public for ordinary Prolog texts.

Examples:
?- member(X,[1,2,3]).
X = 1 ;
X = 2 ;
X = 3

?- member2([2,3],X,1).
Error: Undefined, private or package local predicate member2/3.

Normal Prolog texts can be turned into modules via the predicate module/2. For a nameless module the name user can be used. A further convenience is the predicate use_module/1 which does an ensure loaded of the given file specification. Instead of the predicate use_module/1 also the predicate reexport/1 can be used. The later predicate will make the corresponding imported members visible to qualified invocations and client imports.

Examples:
?- absolute_file_name(library(basic/lists), Y), 
source_property(Y, package(X)).
X = library(jekpro/frequent/basic)

?- absolute_file_name(library(basic/lists), Y),
source_property(Y, sys_source_name(X)).
X = lists

The path resolution uses prefixes from the current source and the system sources along the knowledge bases. The prefixes for the current source can be set via the predicates package/1 and use_package/1. The prefixes for the system sources can be set via the predicate set_source_property/2. The prefixes can be queried via the source_property/2 predicate.

The following module system predicates are provided:

package(P):
The predicate adds the prefix P to the list of prefixes of the current source. Currently library/1 and foreign/1 prefixes are supported. The prefix is also used as a prefix to the module/2 directive.
use_package(P):
The predicate adds the prefix P to the list of prefixes of the current source. Currently library/1 and foreign/1 prefixes are supported. The prefix is not used as a prefix to the module/2 directive.
module(N, L):
The predicate is a convenience for a combination of setting the module name to N, setting the source to package and setting the members L to public.
use_module(R):
The predicate imports the read path R with making its predicates and syntax operators visible.
reexport(R):
The predicate imports the read path R with making its predicates and syntax operators visible. The predicates and syntax operators along the reexport chain become also visible.
sys_auto_load(R):
The predicate imports the read path R without making its predicates and syntax operators visible.
sys_load_resource(R):
The predicate imports the read path R trying resolve it to a resource bundle instead of a Prolog text.
sys_add_resource(R):
Add the read path R to the list of error resources.
private P, ..:
The predicate sets the member P to private.
public P, ..:
The predicate sets the member P to public.
override I, …:
The predicate sets the predicate indicator I to override.

The following predicate and evaluable function properties for the module system are provided:

visible(V):
The property indicates that the predicate or evaluable function has visibility V. The argument V can have the values “public” and “private”. The property is single valued and can be missing.
sys_public(S):
The property indicates that the predicate or evaluable function has been marked public in source context S. The property is multi valued and can be missing. The property can be changed.
sys_private(S):
The property indicates that the predicate or evaluable function has been marked private in source context S. The property is multi valued and can be missing.
override(S):
The property indicates that the predicate has been marked override in source context S. The property is multi valued and can be missing. The property can be changed.
The following operator properties for the module system are provided:
visible(V):
The property indicates that the syntax operator has visibility V. The argument V can have the values “public” and “private”. The property is single valued and can be missing. The property can be changed.
override:
The property indicates that the override warning for this operator is suppressed. The property is single valued and can be missing. The property can be changed.

The following source properties for the module system are provided:

sys_source_preload:
The property indicates that the source is preload. The property is single valued and can be missing. The property can be changed for user sources.
sys_source_visible(V):
The property indicates that the source has default visibility V for their members. The argument V can have the values “public” and “private”. The property is single valued and can be missing. The property can be changed for user sources.
sys_source_name(N):
The property indicates that the source has the module package and name N. The property is single valued and can be missing. The property can be changed for user sources.
sys_timing(T):
The property indicates the time spent for consult, ensure loaded or unload in milliseconds. The property cannot be changed.
sys_link(S, M):
The property indicates that this source is linked to the source S with visibility and export mode M. The mode M can take the values use_module, reexport, sys_auto_load, sys_load_resource and sys_parent_module. The property is multi-value and can be missing. The property cannot be changed.
package(P):
The property indicates that this source has prefix P and that the name of the source has also this prefix. The prefix P can be a compound with functor library/1 or foreign/1. The argument of the compound should be a package. The property is single-valued and can be missing. The property can be changed.
use_package(P):
The property indicates that this source has prefix P, but it doesn’t put forward a prefix for the source name. The prefix P can be a compound with functor library/1 or foreign/1. The argument of the compound should be a package. The property is multi-value and can be missing. The property can be changed.

Kommentare