prolog_autoload.pl -- Autoload all dependencies
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.
- autoload_all is det
- autoload_all(+Options) is det
- Force all necessary autoloading to be done now. This sets the
Prolog flag
autoload
tofalse
, 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
(defaultfalse
), report on the files loaded. - undefined(+Action)
- Action defines what happens if the analysis finds a
definitely undefined predicate. One of
ignore
orerror
. Default isignore
.
- autoload_step(-NewFiles, -NewPreds, +Options) is det[private]
- Scan through the program and autoload all undefined referenced predicates.
- 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).
- report_undefined(+Undefined) is det[private]
Undocumented predicates
The following predicates are exported, but not or incorrectly documented.