C.2.1.1 Loading XSB source files
SWI-Prolog's emulation of XSB depends on the XSB preferred file name
extension .P
. This extension is used by
library(dialect/xsb/source)
to initiate a two phase loading
process based on term_expansion/2
of the virtual term begin_of_file
.
- In the first phase the file is read with XSB compatible operator
declarations and all directives (:- Term) are extracted. The directives
are used to determine that the file defines a module (iff the file
contains an export/1
directive) and construct a SWI-Prolog compatible module declaration. As
XSB has a two phase compiler where SWI has a single phase compiler, this
is also used to move some directives to the start of the file.
- The second phase loads the file as normal.
To load a project in both XSB and SWI-Prolog it is advised to make
sure all source files use the .P
file name extension. Next,
write a SWI-Prolog loader in a .pl
file that contains e.g.,
:- use_module(library(dialect/xsb/source)). :- [main_file].
It is also possible to put the able use_module/1 directive in your personal initialization file (see section 2.2), after which XSB files can be loaded as normal SWI-Prolog files using
% swipl file.P
XSB code may depend on the gpp
preprocessor. We do not provide gpp. It is however possible to
send XSB source files through gpp by loading library(library/dialect/xsb/gpp)
.
This require gpp to be accessible through the environment
variable PATH
or the file_search_path/2
alias path
. We refer to the gpp
library for
details.