next up previous index
Next: Other Modular Items Up: Module System Previous: Visibility of Predicates   Index


Libraries

A library is usually implemented in a module so that its implementation details are hidden to the outside. Its access is done through its module interface.

The library is made available using use_module(library(...)) or lib/1 which will search for the file (specified as argument) in the library path (see get_flag/2), compile it and make its interface available in the caller module.

Name clashes are reported when two predicates of the same name exist in two different imported libraries. This event is a warning; the predicate defined in the last imported library is imported. It is possible to prevent the name clash by explicitly importing the predicate that causes the name clash with import_from/2 and then import the library, or to cancel the link using abolish/1.

A useful predicate when writing a library that must redefine an existing predicate using its previous definition is :/2. This predicate calls the goal in its first argument like with call/1 except that the predicate called (it must be global or exported) is the one defined in the module specified in the second argument. For example, to redefine the built-in at/2 switching the 2 arguments we can do:

at(Pointer, Stream) :-
     sepia_kernel:at(Stream, Pointer).
Note that the caller module of the goal argument will be the same as the caller module of :/2. The purpose of :/2. is to specify another predicate than the visible one whereas the purpose of @/2 is to call the goal in its first argument with the second argument as caller module.


next up previous index
Next: Other Modular Items Up: Module System Previous: Visibility of Predicates   Index

1999-08-06