Prolog 编译错误"Undefined reference to predicate"



我们刚刚开始在我的一个编程类中使用Prolog。我犯了一些错误,我不完全确定是什么原因造成的。这是家庭作业,所以我不期待任何书面答案,但任何提示都将不胜感激。

这是我的代码:

/* Database for family. It consists of facts and rules. */
/* Facts */
male(mark).
/* Question 1.1 */
male(tom).
male(eric).
male(josh). 
male(austin).
/* Question 1.1 */      
female(jen).
female(beth).
female(lisa).
female(alice).
female(alex).
father_of(mark, beth). /* mark is the father of beth */
/* Question 1.1
father_of(josh, eric).
father_of(eric, mark).
father_of(eric, jen).
father_of(austin, alice).
mother_of(jen, tom). /* jen is the mother of tom */
/* Question 1.1
mother_of(lisa, eric).
mother_of(alex, alice).
mother_of(alice, jen).
mother_of(alice, mark).
/* Rules */
is_male(X) :-
male(X);
father_of(X, _).
/* Question 1.2 */
is_female(X) :-
    female(X);
    mother_of(X, _).
/* Question 1.3 */
grandfather_of(X, Z) :-
  father_of(X, Y), 
  (mother_of(Y, Z); father_of(Y, Z)).

grandmother_of(X, Z) :- 
    mother_of(X, Y), 
    (mother_of(Y, Z); father_of(Y, Z)).

我收到的错误:/tmp/gplc0GI9tg.o:在函数"Lpred7_1"中:

(.text+0x2d1):未定义对predicate(mother_of/2)' /tmp/gplc0GI9tg.o: In function谓词的引用(grandfather_of/2)':

(.text+0x35d):未定义对predicate(mother_of/2)' /tmp/gplc0GI9tg.o: In function谓词的引用(grandmaster_of/2)':

(.text+0x3a8):未定义对predicate(mother_of/2)' /tmp/gplc0GI9tg.o: In function谓词的引用(grandmaster_of/2)':

(.text+0x3ed):未定义对"谓词(mother_of/2)"的引用collect2:错误:ld返回1退出状态编译失败

查看您的代码片段,以下几行是伪造的:

/* Question 1.1
father_of(josh, eric).

同样的事情,不久后:

/* Question 1.1
mother_of(lisa, eric).

我想你想在写下以下事实之前结束各自的评论。

最佳实践:只要行末注释足够,就使用它们(从%开始)。

最新更新