Alias(Name)
, e.g., library(lists)
. This
feature is best described using an example. Given the definition:
file_search_path(demo, '/usr/lib/prolog/demo').
the file specification demo(myfile)
will be expanded to
/usr/lib/prolog/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>)
and 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
use_foreign_library/1.
user:(file_search_path(library, Dir) :- library_directory(Dir)). user:file_search_path(swi, Home) :- current_prolog_flag(home, Home). user:file_search_path(swi, Home) :- current_prolog_flag(shared_home, Home). user:file_search_path(library, app_config(lib)). user:file_search_path(library, swi(library)). user:file_search_path(library, swi(library/clp)). user:file_search_path(foreign, swi(ArchLib)) :- current_prolog_flag(apple_universal_binary, true), ArchLib = 'lib/fat-darwin'. user:file_search_path(foreign, swi(ArchLib)) :- \+ current_prolog_flag(windows, true), current_prolog_flag(arch, Arch), atom_concat('lib/', Arch, ArchLib). user:file_search_path(foreign, swi(ArchLib)) :- current_prolog_flag(msys2, true), current_prolog_flag(arch, Arch), atomic_list_concat([lib, Arch], /, ArchLib). user:file_search_path(foreign, swi(SoLib)) :- current_prolog_flag(msys2, true), current_prolog_flag(arch, Arch), atomic_list_concat([bin, Arch], /, SoLib). user:file_search_path(foreign, swi(SoLib)) :- ( current_prolog_flag(windows, true) -> SoLib = bin ; SoLib = lib ). user:file_search_path(path, Dir) :- getenv('PATH', Path), ( current_prolog_flag(windows, true) -> atomic_list_concat(Dirs, (;), Path) ; atomic_list_concat(Dirs, :, Path) ), '$member'(Dir, Dirs). user:file_search_path(user_app_data, Dir) :- '$xdg_prolog_directory'(data, Dir). user:file_search_path(common_app_data, Dir) :- '$xdg_prolog_directory'(common_data, Dir). user:file_search_path(user_app_config, Dir) :- '$xdg_prolog_directory'(config, Dir). user:file_search_path(common_app_config, Dir) :- '$xdg_prolog_directory'(common_config, Dir). user:file_search_path(app_data, user_app_data('.')). user:file_search_path(app_data, common_app_data('.')). user:file_search_path(app_config, user_app_config('.')). user:file_search_path(app_config, common_app_config('.')). user:file_search_path(app, swi(app)). user:file_search_path(app, app_data(app)).
The '$xdg_prolog_directory'/2 uses either the XDG Base Directory or win_folder/2 on Windows. On Windows, user config is mapped to roaming appdata (CSIDL_APPDATA), user data to the non-roaming (CSIDL_LOCAL_APPDATA) and common data to (CSIDL_COMMON_APPDATA).
The file_search_path/2 expansion is used by all loading predicates as well as by absolute_file_name/[2,3].
The Prolog flag verbose_file_search
can be set to true
to help debugging Prolog's search for
files.