-->

序言:第不在一起的源文件(Prolog: Clauses are not together in s

2019-09-01 23:05发布

我有这样的代码:

% Family tree
female(pen).
male(tom).
male(bob).
female(liz).
female(pat).
female(ann).
male(jim).

parent(pam, bob).
parent(tom, bob).
parent(tom, liz).
parent(bob, ann).
parent(bob, pat).
parent(pat, jim).

我得到这个错误:

Warning: Clauses of female/1 are not together in source-file
Warning: Clauses of male/1 are not together in source-file

这是什么错误的目的是什么?
我的意思是,文件没有编译和运行得很好,我知道错误的意思。 但为什么?
这只是强制执行最佳实践的通知?

我是很新的逻辑编程。
谢谢!

Answer 1:

正确的,这是实施最佳做法,就是把所有相关的条款一起在源文件中的警告。 除此之外,条款彼此在源文件中接近不要紧,只要它们的相对顺序不会改变。



Answer 2:

警告鼓励最佳实践,帮助现货错别字。 这里有一个错字例如:

small(ant).
small(fly).
small(molecule).

smell(sweet).
smell(pungent).
small(floral).

这个错误是很难发现,但幸运的是编译器警告:

Warning: /tmp/test.pl:7:
Clauses of small/1 are not together in the source-file

随着警报和线路错误,人们可以找到并更快地纠正这个错误。

ISO Prolog的提供discontiguous/1指令关闭此警告特定谓词。 请参阅规范的部分7.4.2.3。 它使用如下:

:- discontiguous small/1.


文章来源: Prolog: Clauses are not together in source-file