adding a search Path in SWI prolog

2020-07-09 06:33发布

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 !

标签: prolog
2条回答
仙女界的扛把子
2楼-- · 2020-07-09 07:08

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)

查看更多
萌系小妹纸
3楼-- · 2020-07-09 07:14

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

 :- multifile(library_directory/1).
 library_directory('/home/ulrich/lftp/Prolog-inedit').
查看更多
登录 后发表回答