Did you know ... Search Documentation:
prolog_autoload.pl -- Autoload all dependencies
PublicShow source

The autoloader is there to smoothen program development. It liberates the programmer from finding the library that defines some particular predicate and including the proper use_module/1,2 directive in the sources. This is even better at the toplevel, where just using maplist/3 is way more comfortable than first having to load library(apply). In addition, it reduces the startup time of applications by only loading the necessary bits.

Of course, there is also a price. One is that it becomes less obvious from where some predicate is loaded and thus whether you have the right definition. The second issue is that it is harder to create a stand-alone executable because this executable, without access to the development system, can no longer rely on autoloading.

This library provides autoload_all/0 and autoload_all/1 to autoload all predicates that are referenced by the program. Now, this is in general not possible in Prolog because the language allows for constructing arbitrary goals and runtime and calling them (e.g., read(X), call(X)).

The implementation relies on code analysis of the bodies of all clauses and all initialization goals.

As of SWI-Prolog 8.1.22 the system provides autoload/1,2 directives that mitigate the possible ambiguity.

Source autoload_all is det
Source autoload_all(+Options) is det
Force all necessary autoloading to be done now. This sets the Prolog flag autoload to false, resolving explicit autoloading and then finds all undefined references to autoloadable predicates and load the library files that define these predicates.

Options:

verbose(+Boolean)
If true (default false), report on the files loaded.
undefined(+Action)
Action defines what happens if the analysis finds a definitely undefined predicate. One of ignore or error. Default is ignore.

Re-exported predicates

The following predicates are exported from this file while their implementation is defined in imported modules or non-module files loaded by this module.

Source autoload_all is det
Source autoload_all(+Options) is det
Force all necessary autoloading to be done now. This sets the Prolog flag autoload to false, resolving explicit autoloading and then finds all undefined references to autoloadable predicates and load the library files that define these predicates.

Options:

verbose(+Boolean)
If true (default false), report on the files loaded.
undefined(+Action)
Action defines what happens if the analysis finds a definitely undefined predicate. One of ignore or error. Default is ignore.