![]() |
YAP 7.1.0
|
Files | |
file | newmod.yap |
support for creating a new module | |
class use_module/1 |
use_module( +Files )
properties: directive
loads a module file
This predicate loads the file specified by Files, importing all their public predicates into the current type-in module It is implemented as if by:
Notice that Files may be a single file, or a list with a number files The Files are loaded in YAP only once, even if they have been updated meanwhile YAP should also verify whether the files actually define modules Please consult load_files/3 for other options when loading a file
Predicate name clashes between two different modules may arise, either when trying to import predicates that are also defined in the current type-in module, or by trying to import the same predicate from two different modules
In the first case, the local predicate is considered to have priority and use_module/1 simply gives a warning As an example, if the file a.pl
contains:
and the file b.pl
contains:
YAP will execute as follows:
The example shows that the query a(X)
has a single answer, the one defined in a.pl
Calls to a(X)
succeed in the top-level, because the module a
was loaded into user
On the other hand, b(X)
is not exported by a.pl
, and is not available to calls, although it can be accessed as a predicate in the module 'a' by using the :
operator
Next, consider the three files c.pl
, d1.pl
, and d2.pl
:
The result is as follows:
The state of the module system after this error is undefined
\pred module(+ M:atom,+ L:list ) is directive the current file defines module M with exports L The list may include
The list L may include predicates imported from other modules If you want to fully reexport a module, or a sub-set, also consider reexport/1
Similar to module/2 , this directive defines the file where it appears in as a module file; it must be the first declaration in the file M must be an atom specifying the module name; L must be a list containing the module's public predicates specification, in the form [predicate_name/arity,...]
The last argument Options must be a list of options, which can be:
false
, keep source code for current module, if true
, disableNote that predicates are normally exported using the directive module/2
The export/1
argumwnt is meant to allow export from dynamically created modules The directive argument may also be a list of predicates
properties: directive
load a module file
This predicate loads the file specified by Files, importing all their public predicates into the current type-in module It is implemented as if by:
Notice that Files may be a single file, or a list with a number files The Files are loaded in YAP only once, even if they have been updated meanwhile YAP should also verify whether the files actually define modules Please consult load_files/3 for other options when loading a file
Predicate name clashes between two different modules may arise, either when trying to import predicates that are also defined in the current type-in module, or by trying to import the same predicate from two different modules
In the first case, the local predicate is considered to have priority and use_module/1 simply gives a warning As an example, if the file a.pl
contains:
and the file b.pl
contains:
YAP will execute as follows:
The example shows that the query a(X)
has a single answer, the one defined in a.pl
Calls to a(X)
succeed in the top-level, because the module a
was loaded into user
On the other hand, b(X)
is not exported by a.pl
, and is not available to calls, although it can be accessed as a predicate in the module 'a' by using the :
operator
Next, consider the three files c.pl
, d1.pl
, and d2.pl
:
The result is as follows:
The state of the module system after this error is undefined
class use_module/2 |
use_module(+Files, +Imports)
loads a module file but only imports the named predicates
This predicate loads the file specified by Files, importing their public predicates specified by Imports into the current type-in module It is implemented as if by:
The Imports argument may be use to specify which predicates one wants to load It can also be used to give the predicates a different name As an example, the graphs library is implemented on top of the red-black trees library, and some predicates are just aliases:
Unfortunately it is still not possible to change argument order
loads a module file but only imports the named predicates
This predicate loads the file specified by Files, importing their public predicates specified by Imports into the current type-in module It is implemented as if by:
The Imports argument may be use to specify which predicates one wants to load It can also be used to give the predicates a different name As an example, the graphs library is implemented on top of the red-black trees library, and some predicates are just aliases:
Unfortunately it is still not possible to change argument order
class use_module/3 |
use_module(? M,? F,+ L)
SICStus directive for loading a module, it can operate in two different ways:
class current_module/1 |
current_module( ? Mod:atom)
properties: nondeterministic
Succeeds if M is a user-visible modules A module is defined as soon as some predicate defined in the module is loaded, as soon as a goal in the module is called, or as soon as it becomes the current type-in module
class current_module/2 |
current_module( ? Mod:atom, ? F : file )
properties: nondeterministic
Succeeds if M is a module associated with the file F, that is, if File is the source for M If M is not declared in a file, F unifies with user
class abolish_module/1 |
abolish_module( + Mod)
properties: deterministic
get rid of a module and of all predicates included in the module
class set_base_module/1 |
set_base_module( +Expor tingModule )
properties: deterministic
All predicates exported from ExportingModule are automatically available to the other source modules
This built-in was introduced by SWI-Prolog In YAP, by default, modules only inherit from prolog
This extension allows predicates in the current module (see module/2 and module/1 ) to inherit from user
or other modules
Definition at line 2 of file modules.yap.
class import_module/2 |
import_module( +ImportingModule, +ExportingModule )
properties: deterministic
All exported predicates from ExportingModule are automatically available to the source module ImportModule
This innovation was introduced by SWI-Prolog By default, modules only inherit from prolog
and user
This extension allows predicates in any module to inherit from user
and other modules
class add_import_module/3 |
add_import_module( + Module, + ImportModule , +_Pos_)
properties: deterministic
Add all exports in ImportModule as available to Module
All exported predicates from ExportModule are made available to the source module ImportModule If Position is bound to start
the module ImportModule is tried first, if Position is bound to end
, the module is consulted last
class delete_import_module/2 |
delete_import_module( + ExportModule, + ImportModule )
properties: deterministic
Exports in ImportModule are no longer available to Module
All exported predicates from ExportModule are discarded from the ones used vy the source module ImportModule
class module_property/2 |
module_property( +Module, ? Property )
properties: nondeterministic
Enumerate non-deterministically the main properties of Module
Reports the following properties of Module:
class
( ?_Class_ ): whether it is a system
, library
, or user
moduleline_count
(?_Ls_): number of lines in source file (if there is one)file
(?_F_): source file for Module (if there is one)exports
(-Es): list of all predicate symbols and operator symbols exported or re-exported by this module