Load from where?
"The specification for a source file is handed to absolute_file_name/2."
Means:
If you specify the relative path of a file, then the absolute filename depends on swipl's current directory.
If you want to load a file relative to the library search path, then tag the relative filename with library()
.
For example, after having put directory code
on the library search path using
assertz(file_search_path(library,'my/directory/code')).
and the file to be loaded is
. ├── heavycarbon │ └── strings │ └── meta_helpers_nonmodular.pl
Then the following can be done from modules or directiveless from the toplevel REPL:
:- load_files([library(heavycarbon/strings/meta_helpers_nonmodular)]). :- load_files([library('heavycarbon/strings/meta_helpers_nonmodular')]). :- load_files([library('heavycarbon/strings/meta_helpers_nonmodular.pl')]). % I prefer this; be explicit!
Note that you cannot write
:- load_files([library(heavycarbon/strings/meta_helpers_nonmodular.pl)]).
because that term looks like it contains a dict operation to Prolog.
Can't load multiple times
At include/1, we read: Textually including files that contain clauses is less obvious. Normally, in SWI-Prolog, clauses are owned by the file in which they are defined.
This seems to be the basic problem with loading the same file from several modules. You then get:
ERROR: load_files/2: No permission to load source `'file.pl' (Non-module file already loaded into module foo; trying to load into bar)
The fall back is to use include/1, which recreates the clauses in the file to-load inside the module into which the file is included. Sometimes that makes sense.