use_module/1

start using default definition of module.%

use_module( +Files )* is 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:


 use_module(F) :-
 load_files(F, [if(not_loaded),must_be_module(true)]).

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//33 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//11 simply gives a warning. As an example, if the file a.pl contains:


 :- module( a, @ref U5bUaU2fU_1 "[a//1" 1] ).

 :- use_module(b).

 a(1).
 a(X) :- b(X).

and the file b.pl contains:


 :- module( b, @ref U5bUaU2fU_1 "[a//1" @ref 1U2cUbU2fU_1 "1,b//1" 1] ).

 a(2).

 b(1).

YAP will execute as follows:


 ?- [a].
 % consulting .../a.pl...
 % consulting .../b.pl...
 % consulted .../b.pl in module @ref bU2cUU20U_0 "b, /0"0 msec 0 bytes
 % consulted .../a.pl in module a, 1 msec 0 bytes
 true.
 ?- a(X).
 X = 1 ? ;
 X = 1.

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:


 % c.pl
 :- module( c, @ref U5bUaU2fU_1 "[a//1" 1] ).

 :- use_module([d1, d2]).

 a(X) :-
 b(X).
 a(X) :-
 c(X).
 a(X) :-
 d(X).

 % d1.pl
 :- module( d1, @ref U5bUbU2fU_1 "[b//1" @ref 1U2cUcU2fU_1 "1,c//1" 1] ).

 vvb(2).
 c(3).


 % d2.pl
 :- module( d2, @ref U5bUbU2fU_1 "[b//1" @ref 1U2cUdU2fU_1 "1,d//1" 1] ).

 b(1).
 d(4).

The result is as follows:


 ./yap -l c
 YAP 6.3.4 (x86_64-darwin13.3.0): Tue Jul 15 10:42:11 CDT 2014

 ERROR!!
 at line 3 in o/d2.pl,
 PERMISSION ERROR- loading .../c.pl: modules d1 and d2 both define b/1
 ?- a(X).
 X = 2 ? ;
 ERROR!!
 EXISTENCE ERROR- procedure @ref cU2fU_1 "c//1" 1 is undefined, called from context @ref prologU3aUU24Uuser_callU2fU_2 "prolog:$user_call//2" 2
 Goal was c:c(_131290)

The state of the module system after this error is undefined.