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.
Source autoload_step(-NewFiles, -NewPreds, +Options) is det[private]
Scan through the program and autoload all undefined referenced predicates.
Arguments:
NewFiles- is unified to the number of files loaded
NewPreds- is unified to the number of predicates imported using the autoloader.
Source walk_options(+AutoloadOptions, -WalkOptions) is det[private]
Construct the option list for the code walker. If we see an undefined predicate, we must collect these rather than printing them or immediately terminating with an exception. This reuses code from library(check).
Source report_undefined(+Undefined) is det[private]

Undocumented predicates

The following predicates are exported, but not or incorrectly documented.

Source autoload_all(Arg1)