In many Prolog systems it is easy to add a new search path for consulting file. In Yap for example, the predicate I know it is add_to_path(NewPath). Is there a way to do the same in SWI Prolog ?. My question is specifically about adding one path to the already existing paths, I am aware of the file_search_path/2 predicate for declaring directories, and the cd/1 predicate for changing the current directory, but I would like to know if there is an alternative method, like the one I found in Yap.
thanks in advance !
There are several mechanisms to this. The first one I met was in C-Prolog, which indeed used clauses for library_directory/1
. The current SWI-Prolog mechanism is derived from Quintus and also used in SICStus. It generalises from the library_directory/1
approach
be treating expressions of the form <alias>(Path)
as a search over the path-alias <alias>
.
Paths for an alias are defined using the predicate file_search_path/2. Now, library
is just an alias. Normally, libraries are added using a clause file_search_path(library, Dir)
.
This mechanism has proven to be pretty flexible. Of course, it would be nice if Prolog systems get more compatible here. I think todays YAP also supports the file_search_path
system. (2016 Edit: It does indeed, see YAP Prolog User's Manual: Changing the Compiler’s Behavior)
In your .plrc
/.yaprc
/.sicstusrc
/.swiplrc
:
:- multifile(library_directory/1).
library_directory('/home/ulrich/lftp/Prolog-inedit').
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With