3.1.1.3 Sub-projects using search paths
Thanks to Quintus, Prolog adapted an extensible mechanism for searching files using file_search_path/2. This mechanism allows for comfortable and readable specifications.
Suppose you have extensive library packages on graph algorithms, set operations and GUI primitives. These sub-projects are likely candidates for re-use in future projects. A good choice is to create a directory with sub-directories for each of these sub-projects.
Next, there are three options. One is to add the sub-projects to the directory hierarchy of the current project. Another is to use a completely dislocated directory. Third, the sub-project can be added to the SWI-Prolog hierarchy. Using local installation, a typical file_search_path/2 is:
:- prolog_load_context(directory, Dir), asserta(user:file_search_path(myapp, Dir)). user:file_search_path(graph, myapp(graph)). user:file_search_path(ui, myapp(ui)).
When using sub-projects in the SWI-Prolog hierarchy, one should use
the path alias swi
as basis. For a system-wide
installation, use an absolute path.
Extensive sub-projects with a small well-defined API should define a load file with calls to use_module/1 to import the various library components and export the API.