简体   繁体   English

将知识库与谓词分离,得到“未定义过程”

[英]Separating Knowledge Base from Predicates, get "undefined procedure"

Why isn't father/2 recognized and why can't I load a file that calls father/2 ?为什么father/2没有被识别,为什么我不能加载调用father/2的文件?

theogony.pl神谱

father(kronos, zeus).
father(zeus, ares).

mythos.pl神话.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).

swipl挥动

?- consult('mythos.pl'). 
   false.
?- consult('theogony.pl').
   true.
?- father(X,zeus).
   ERROR: Unknown procedure: father/2 (DWIM could not correct goal)

As noted there are two Prolog files with the file type pl .如前所述,有两个文件类型为pl的 Prolog 文件。 This code works with both files in the same directory, eg 'C:/Users/Groot/Example_01'.此代码适用于同一目录中的两个文件,例如“C:/Users/Groot/Example_01”。 You can use another directory but be consistent with the directory name.您可以使用另一个目录,但要与目录名称保持一致。

Directory: 'C:/Users/Groot/Example_01'目录:'C:/Users/Groot/Example_01'
File: 'theogony.pl'文件:'theogony.pl'

:- module(theogony,
    [
        father/2
    ]).

father(kronos, zeus).
father(zeus, ares).

Directory: 'C:/Users/Groot/Example_01'目录:'C:/Users/Groot/Example_01'
File: 'mythos.pl'文件:'mythos.pl'

:- module(mythos,
    [
        ancestor/2
    ]).

ancestor(X,Y) :-
    father(X,Y).

ancestor(X,Y) :-
    ancestor(X,Z),
    ancestor(Z,Y).

Start SWI-Prolog启动 SWI-Prolog

Welcome to SWI-Prolog (threaded, 64 bits, version 8.5.15)
...

?- 

I know, there is a newer version but this is so basic even the really old versions should work.我知道,有一个更新的版本,但这是非常基本的,即使是真正的旧版本也应该可以工作。

Change the working directory.更改工作目录。

?- working_directory(_,'C:/Users/Groot/Example_01').
true.

Use consult which is also done using [] to load the Prolog files.使用同样使用[]加载 Prolog 文件的咨询。

?- [theogony].
true.

?- [mythos].
true.

Run your query.运行您的查询。

?- father(X,zeus).
X = kronos.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM