Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding a search Path in SWI prolog

Tags:

prolog

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 !

like image 506
Sergio Avatar asked Jun 13 '11 17:06

Sergio


2 Answers

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)

like image 190
Jan Wielemaker Avatar answered Sep 28 '22 09:09

Jan Wielemaker


In your .plrc/.yaprc/.sicstusrc/.swiplrc:

 :- multifile(library_directory/1).
 library_directory('/home/ulrich/lftp/Prolog-inedit').
like image 41
false Avatar answered Sep 28 '22 09:09

false