我正在学习序言,并且对select/3
谓词有疑问,所以我为此做了一个测试文件。
我要运行的整个代码是XSB在其自己文件中的以下1行:
find(X,B) :- select(X, [1,2,3,4,5], B).
它可以正常编译,但是出现以下错误:
| ?- find(5,B).
++Error[XSB/Runtime/P]: [Existence (No procedure usermod : select / 3 exists)] []
Forward Continuation...
... machine:xsb_backtrace/1 From c:/program files (x86)/XSB/syslib/machine.xwam
... x_interp:_$call/1 From c:/program files (x86)/XSB/syslib/x_interp.xwam
... x_interp:call_query/1 From c:/program files (x86)/XSB/syslib/x_interp.xwam
... standard:call/1 From c:/program files (x86)/XSB/syslib/standard.xwam
... standard:catch/3 From c:/program files (x86)/XSB/syslib/standard.xwam
... x_interp:interpreter/0 From c:/program files (x86)/XSB/syslib/x_interp.xwam
... loader:ll_code_call/3 From c:/program files (x86)/XSB/syslib/loader.xwam
... loader:load_object_file/2 From c:/program files (x86)/XSB/syslib/loader.xwam
... standard:call/1 From c:/program files (x86)/XSB/syslib/standard.xwam
... standard:catch/3 From c:/program files (x86)/XSB/syslib/standard.xwam
AFAIK,此错误通常是在用户定义谓词存在问题时出现的,但这是标准功能,并且文档说它会自动导入,所以为什么会出现此错误?
答案 0 :(得分:2)
select/3
谓词是常见的库谓词。似乎,尽管使用XSB,您仍在阅读另一个Prolog系统文档。可能是SWI-Prolog,它提供了XSB中不存在的自动加载机制。但是您可以手动导入谓词。例如:
$ xsb
[xsb_configuration loaded]
[sysinitrc loaded]
[xsbbrat loaded]
XSB Version 3.8.0 (Three-Buck Chuck) of October 28, 2017
[i386-apple-darwin18.7.0 64 bits; mode: optimal; engine: slg-wam; scheduling: local]
[Build date: 2019-12-13]
| ?- import select/3 from lists.
yes
| ?- select(X, [1,2,3,4,5], B).
X = 1
B = [2,3,4,5];
X = 2
B = [1,3,4,5];
X = 3
B = [1,2,4,5];
X = 4
B = [1,2,3,5];
X = 5
B = [1,2,3,4];
no
要将导入添加到您的源文件中,请将其作为指令写入文件的开头:
:- import select/3 from lists.