[英]Separating Knowledge Base from Predicates, get "undefined procedure"
为什么father/2
没有被识别,为什么我不能加载调用father/2
的文件?
神谱
father(kronos, zeus).
father(zeus, ares).
神话.pl
consult('theogony.pl').
%% --
%% X is an ancestor of Y
%% --
ancestor(X,Y) :-
father(X,Y).
ancestor(X,Y) :-
ancestor(X,Z),
ancestor(Z,Y).
挥动
?- consult('mythos.pl').
false.
?- consult('theogony.pl').
true.
?- father(X,zeus).
ERROR: Unknown procedure: father/2 (DWIM could not correct goal)
如前所述,有两个文件类型为pl
的 Prolog 文件。 此代码适用于同一目录中的两个文件,例如“C:/Users/Groot/Example_01”。 您可以使用另一个目录,但要与目录名称保持一致。
目录:'C:/Users/Groot/Example_01'
文件:'theogony.pl'
:- module(theogony,
[
father/2
]).
father(kronos, zeus).
father(zeus, ares).
目录:'C:/Users/Groot/Example_01'
文件:'mythos.pl'
:- module(mythos,
[
ancestor/2
]).
ancestor(X,Y) :-
father(X,Y).
ancestor(X,Y) :-
ancestor(X,Z),
ancestor(Z,Y).
启动 SWI-Prolog
Welcome to SWI-Prolog (threaded, 64 bits, version 8.5.15)
...
?-
我知道,有一个更新的版本,但这是非常基本的,即使是真正的旧版本也应该可以工作。
更改工作目录。
?- working_directory(_,'C:/Users/Groot/Example_01').
true.
使用同样使用[]
加载 Prolog 文件的咨询。
?- [theogony].
true.
?- [mythos].
true.
运行您的查询。
?- father(X,zeus).
X = kronos.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.