在 SWI prolog 中添加搜索路径 [英] adding a search Path in SWI prolog

查看:34
本文介绍了在 SWI prolog 中添加搜索路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在许多 Prolog 系统中,很容易为咨询文件添加新的搜索路径.例如,在 Yap 中,我知道的谓词是 add_to_path(NewPath).有没有办法在 SWI Prolog 中做同样的事情?.我的问题特别是关于向现有路径添加一个路径,我知道用于声明目录的 file_search_path/2 谓词和用于更改当前目录的 cd/1 谓词,但我想知道是否有替代方法方法,就像我在 Yap 找到的方法.

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.

提前致谢!

推荐答案

对此有多种机制.我遇到的第一个是在 C-Prolog 中,确实使用了library_directory/1 的子句.当前的 SWI-Prolog 机制源自 Quintus,也在 SICStus 中使用.它概括了 library_directory/1 方法将 (Path) 形式的表达式视为对路径别名 的搜索.

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>.

别名的路径使用谓词file_search_path/2.现在,library 只是一个别名.通常,使用子句 file_search_path(library, Dir) 添加库.

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).

事实证明,这种机制非常灵活.当然,如果 Prolog 系统在这里变得更加兼容就更好了.我想今天的 YAP 也支持 file_search_path 系统.(2016 年确实如此,请参阅 YAP Prolog 用户手册:更改编译器的行为)

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 It does indeed, see YAP Prolog User's Manual: Changing the Compiler’s Behavior)

这篇关于在 SWI prolog 中添加搜索路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆