【发布时间】:2017-03-20 14:36:02
【问题描述】:
我在尝试跟踪序言时遇到了一些问题。跟踪日志如下:
parent_of(X,Y).
Call: (6) parent_of(_G2780, _G2781) ? creep
Exit: (6) parent_of(warren, jerry) ? creep
X = warren
Y = jerry ;
Redo: (6) parent_of(_G2780, _G2781) ? creep
Exit: (6) parent_of(maryalice, jerry) ? creep
X = maryalice
Y = jerry ;
Redo: (6) parent_of(_G2780, _G2781) ? creep
Call: (7) brother(_G2865, _G2781) ? creep
Exit: (7) brother(jerry, kather) ? creep
Call: (7) father(_G2780, jerry) ? creep
Call: (8) parent_of(_G2780, jerry) ? creep
Exit: (8) parent_of(warren, jerry) ? creep
Call: (8) male(warren) ? creep
Exit: (8) male(warren) ? creep
Exit: (7) father(warren, jerry) ? creep
Exit: (6) parent_of(warren, kather) ? creep
但是,我声明我的事实和规则如下:
male(jerry).
male(stuart).
male(warren).
male(peter).
female(kather).
female(maryalice).
female(ann)
brother(jerry,stuart).
brother(jerry,kather).
brother(peter, warren).
sister(ann, maryalice).
sister(kather,jerry).
parent_of(warren,jerry).
parent_of(maryalice,jerry).
parent_of(X,Z):- brother(Y,Z),(father(X,Y);mother(X,Y)).
father(X,Y) :- parent_of(X,Y), male(X).
mother(X,Y) :- parent_of(X,Y), female(X).
我以为第一个Call应该执行兄弟和(父亲和母亲)?为什么它直接给了我一个出口,即 Warren 是 Jerry 的父母?
提前致谢!
【问题讨论】:
-
您有语法错误。
female(ann)之后需要一个句号。