我正在尝试根据老歌做家庭作业,我是我自己的爷爷。
所以,我已经开始为谁是儿子、女儿、父亲、父亲_in
_law 等定义规则。
但是,我的规则/事实的顺序一定有问题,因为每次加载它时都会出现以下错误:
GNU Prolog 1.3.1
作者 Daniel Diaz 版权所有 (C) 1999-2009
Daniel Diaz | ?- [爷爷]。正在编译 /home/nfs/student/USER/cs4700/grandpa.pl
以获取字节码...
/home/nfs/student/USER/cs4700/grandpa.pl:119:警告:不连续谓词 child/2 - 子句被忽略
/home /nfs/student/USER/cs4700/grandpa.pl:120:警告:不连续谓词 child/2 - 忽略子句
/home/nfs/student/USER/cs4700/grandpa.pl:121:警告:不连续谓词 child/2 -子句被忽略
/home/nfs/student/USER/cs4700/grandpa.pl:122:警告:不连续谓词 child/2 - 子句被忽略
/home/nfs/student/USER/cs4700/grandpa.pl:123:警告:不连续谓词child/2 - 子句被忽略
/home/nfs/student/USER/cs4700/grandpa.pl:124:警告:不连续谓词 child/2 - 忽略子句
/home/nfs/student/USER/cs4700/grandpa.pl:125:警告:不连续谓词儿子/ 2 - 忽略子句
/home/nfs/student/USER/cs4700/grandpa.pl:126:警告:不连续谓词儿子/2 - 忽略子句
/home/nfs/student/USER/cs4700/grandpa.pl:127:警告:不连续谓词son/2 - 忽略子句
/home/nfs/student/USER/cs4700/grandpa.pl:128:警告:不连续谓词son/2 - 忽略子句
/home/nfs/student/USER/cs4700/grandpa.pl: 129:警告:不连续谓词 son/2 - 忽略子句
/home/nfs/student/USER/cs4700/grandpa.pl:130:警告:不连续谓词女儿/2 - 忽略子句
/home/nfs/student/USER/cs4700/grandpa.pl:131:警告:不连续谓词已婚/2 - 子句已忽略
/home/nfs/student/USER/cs4700/grandpa.pl:132:警告:不连续谓词已婚/ 2 - 子句忽略
/home/nfs/student/USER/cs4700/grandpa.pl:133:警告:不连续谓词已婚/2 - 子句忽略
/home/nfs/student/USER/cs4700/grandpa.pl:134:警告:不连续谓词已婚/2 - 子句被忽略
/home/nfs/student/USER/cs4700/grandpa.pl:135:警告:不连续谓词 son_in_law/2 - 子句被忽略
/home/nfs/student/USER/cs4700/grandpa.pl: 136:警告:不连续谓词father_in_law/2 - 子句被忽略
/home/nfs/student/USER/cs4700/grandpa.pl:137:警告:不连续谓词父亲/2 - 忽略子句
/home/nfs/student/USER/cs4700/grandpa.pl:138:警告:不连续谓词父亲/ 2 - 忽略子句
/home/nfs/student/USER/cs4700/grandpa.pl:139:警告:不连续谓词父亲/2 - 忽略子句
/home/nfs/student/USER/cs4700/grandpa.pl:140:警告:不连续谓词母亲/2 - 忽略子句
/home/nfs/student/USER/cs4700/grandpa.pl:141:警告:不连续谓词母亲/2 - 忽略子句
/home/nfs/student/USER/cs4700/grandpa.pl: 142:警告:不连续的谓词母亲/ 2 - 子句被忽略
/home/nfs/student/USER/cs4700/grandpa.pl:143:警告:不连续谓词 step_mother/2 - 忽略子句
/home/nfs/student/USER/cs4700/grandpa.pl:144:警告:不连续谓词 Brother_in_law/ 2 - 忽略子句
/home/nfs/student/USER/cs4700/grandpa.pl:145:警告:不连续谓词 Brother_in_law/2 - 忽略子句
/home/nfs/student/USER/cs4700/grandpa.pl:146:警告:不连续谓词 uncle/2 - 子句忽略
/home/nfs/student/USER/cs4700/grandpa.pl:147:警告:不连续谓词 step_daughter/2 - 子句忽略
/home/nfs/student/USER/cs4700/grandpa.pl 已编译,读取 149 行 - 写入 8389 字节,44 毫秒
到目前为止,我的代码是:
child(X,Y):-
son(Y,X).
child(X,Y):-
daughter(Y,X).
parent(X,Y):-
father(X,Y).
parent(X,Y):-
mother(X,Y).
son(X,Y):-
child(X,Y),
male(X).
daughter(X,Y):-
child(X,Y),
female(X).
son_in_law(X,Y):-
child(X,Z),
not(child(X,Y)),
married(Z,Y),
male(X).
step_daughter(X,Y):-
child(X,Z),
married(Z,Y),
not(child(X,Y)),
female(X).
brother(X,Y):-
sibling(X,Y),
male(X).
brother_in_law(X,Y):-
parent(Z,X),
parent(Z,Y),
not(sibling(X,Y)),
male(X).
sibling(X,Y):-
parent(Z,X),
parent(Z,Y).
sister(X,Y):-
sibling(X,Y),
female(X).
father(X,Y):-
parent(X,Y),
male(X).
father_in_law(X,Y):-
child(X,Z),
married(Y,Z),
not(child(X,Y)),
male(X).
mother(X,Y):-
parent(X,Y),
female(X).
step_parent(X,Y):-
married(X,Z),
parent(Z,Y),
not(parent(X,Y)).
step_father(X,Y):-
step_parent(X,Y),
male(X).
step_mother(X,Y):-
step_parent(X,Y),
female(X).
grandparent(X,Y):-
parent(X,Z),
parent(Z,Y).
grandmother(X,Y):-
grandparent(X,Y),
female(X).
grandfather(X,Y):-
grandparent(X,Y),
male(X).
grandchild(X,Y):-
child(X,Z),
child(Z,Y).
married(X,Y):-
wife(X,Y),
female(X).
married(X,Y):-
husband(X,Y),
male(X).
uncle(X,Y):-
sibling(X,Z),
parent(Z,Y),
male(X).
aunt(X,Y):-
sibling(X,Z),
parent(Z,Y),
female(X).
male(i).
male(f).
male(s1).
male(s2).
female(w).
female(d).
child(i,f).
child(s1,w).
child(s1,i).
child(s2,d).
child(s2,f).
child(d,w).
son(i,f).
son(s1,w).
son(s1,i).
son(s2,d).
son(s2,f).
daughter(d,w).
married(i,w).
married(w,i).
married(f,d).
married(d,f).
son_in_law(f,i).
father_in_law(i,f).
father(f,i).
father(i,s1).
father(f,s2).
mother(w,s1).
mother(w,d).
mother(d,s2).
step_mother(d,i).
brother_in_law(f,s1).
brother_in_law(s1,f).
uncle(s1,i).
step_daughter(d,i).
我对prolog很陌生,所以我可能只是犯了一些根本性的错误。有人可以帮我指出有关这些错误的正确方向吗?