SWI-Prolog source files normally have a suffix `.pl '. Specifying the suffix is optional. All predicates that handle source files first check whether a file with suffix `.pl ' exists. If not the plain file name is checked for existence. Library files are specified by embedding the file name using the functor library/1. Thus `foo ' refers to `foo.pl ' or `foo ' in the current directory, `library(foo) ' refers to `foo.pl ' or `foo ' in one of the library directories specified by the dynamic predicate library_directory/1.
SWI-Prolog recognises grammar rules as defined in [Clocksin & Mellish, 1981]. The
user may define additional compilation of the source file by defining
the dynamic predicate term_expansion/2. Transformations by this
predicate overrule the systems grammar rule transformations. It is not
allowed to use assert/1, retract/1 or any other database predicate in
term_expansion/2 other than for local computational purposes.
Directives may be placed anywhere in a source file, invoking any predicate. They are executed when encountered. If the directive fails, a warning is printed. Directives are specified by :-/1 or ?-/1. There is no difference between the two.
SWI-Prolog does not have a separate reconsult/1 predicate. Reconsulting is implied automatically by the fact that a file is consulted which is already loaded.
~
, ~<user>
and
$<var>
. File may also be library(Name)
, in which case
the libraries are searched for a file with the specified name. See also
library_directory/1 and file_search_path/2. consult/1 may be
abbreviated by just typing a number of file names in a list. Examples:
With the semantics, we hope to get as closely possible to the clear semantics without the presence of a module system. Applications using modules should consider using use_module/[1,2].
The implementation normally first verifies whether the predicate is already defined. If not, it will search the libraries and load the required library.
SWI-Prolog, having autoloading, does not load the library. Instead it creates a procedure header for the predicate if this does not exist. This will flag the predicate as `undefined'. See also check/0 and autoload/0.
sun% pl -g make -o my_program -c file ...
If `my_program' is started it will first reconsult all source files that have changed since the compilation.
~/lib/prolog
and the system's library
(in this order) are defined. The user may add library directories
using assert/1, asserta/1 or remove system defaults using retract/1.
file_search_path(demo, '~/demo').
the file specification demo(myfile) will be expanded to ' /demo/myfile' . The second argument of file_search_path/2 may be another alias.
Below is the initial definition of the file search path. This path implies swi(Path) refers to a file in the SWI-Prolog home directory. The alias foreign(Path) is intended for storing shared libraries ( .so or .dll files). See also load_foreign_library/[1,2].
file_search_path(library, X) :- library_directory(X). user:file_search_path(swi, Home) :- feature(home, Home). user:file_search_path(foreign, swi(ArchLib)) :- feature(arch, Arch), concat('lib/', Arch, ArchLib). user:file_search_path(foreign, swi(lib)).
The file_search_path/2 expansion is used by all loading predicates as well as by absolute_file_name/2.
Quintus compatibility predicate. See also source_location/2.
option into an intermediate code file. Can be used to perform code optimisations in expand_term/2 under this condition.
%f
' is replaced by the name of the file to be loaded. The
resulting atom is called as a Unix command and the standard output of
this command is loaded. To use the Unix C preprocessor one should
define:
?- preprocessor(Old, '/lib/cpp -C -P %f'), consult(...). Old = none