我们刚开始在我的一个编程课程中学习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
谓词的未定义引用(grandmother_of / 2)':
(。text + 0x3a8):对predicate(mother_of/2)'
/tmp/gplc0GI9tg.o: In function
谓词的未定义引用(grandmother_of / 2)':
(。text + 0x3ed):对谓词(mother_of / 2)'的未定义引用 collect2:错误:ld返回1退出状态 编译失败
答案 0 :(得分:2)
查看您的代码段,以下行是虚假的:
/* Question 1.1
father_of(josh, eric).
同样的事情,不久之后:
/* Question 1.1
mother_of(lisa, eric).
我认为你在写下以下事实之前想结束各自的评论。
最佳做法:只要足够的话,就可以使用行尾注释(以%
开头)。