When compiling a source file to a .ql
file, remember that
clauses are loaded and directives are executed at
run time, not at compile time. Only predicate
declarations are processed at compile time. For instance,
it does not work to include operator declarations or
clauses of user:term_expansion/[2,4]
or
user:goal_expansion/3
or any auxiliary predicates that they
might need, and rely on the new transformations to be effective for
subsequent clauses of the same file or subsequent files of the
same compilation.
Any directives or clauses that affect the compile-time
environment must be loaded prior to compiling source files
to .ql
files. This also holds for meta-predicates called
by the source files but defined elsewhere, for module name
expansion to work correctly. If this separation into files is
unnatural or inconvenient, one can easily ensure that the
compile-time environment is up to date by doing:
| ?- ensure_loaded(Files), fcompile(Files).
Since module name expansion takes place at compile time, the
module into which the file is to be loaded must be known
when compiling to .ql
files. This is no problem for
module-files because the module name is picked from the
module declaration. When non-module-files are
compiled, the file name may be prefixed with the module name
that is to be used for expansion:
| ?- fcompile(Module:Files).
If an .ql
file is loaded into a different module from
which it was compiled for, a warning is issued.