12.1.3 Libraries

Many of the very common predicates are actually predefined in most Prolog implementations in one way or another. If you have been using SWI Prolog, for example, you will probably have noticed that things like append and member are built in. That's a specialty of SWI, however. Other Prolog implementations, like Sicstus for example, don't have them built in. But they usually come with a set of libraries, i.e. modules defining common predicates. These libraries can be loaded using the normal commands for importing modules. When specifying the name of the library that you want to use, you have to tell Prolog that this module is a library, so that Prolog knows where to look for it (namely, not in the directory where your other code is, but at the place where Prolog keeps its libraries). Putting

:- use_module(library(lists)).

at the top of your file, for instance, tells Prolog to load a library called lists. In Sicstus, this library provides basic list processing predicates.

So, libraries can be pretty useful and they can safe you a lot of work. Note, however, that the way libraries are organized and the inventory of predicates provided by libraries are by no means standardized across different Prolog implementations. In fact, the library systems may differ quite a bit. So, if you want your program to run with different Prolog implementations, it might be easier and faster to define your own library modules (using the techniques that we saw in the last section) than to try to work around all the incompatibilities between the library systems of different Prolog implementations.


Patrick Blackburn, Johan Bos and Kristina Striegnitz
Version 1.2.5 (20030212)