大家好,这是我第一次来这里:)!
我有以下 Prolog 定义集,唯一不起作用的是子类。谁能帮我弄清楚为什么这不是:(
% definitions of classes in our system
class(object).
class(animal).
class(cat).
class(dog).
class(dachshund).
class(toy).
class(ball).
class(post).
% definitions of interfaces
interface(iwoof).
interface(imeow).
% definitions of class inheritance
inherits(animal,object).
inherits(cat,animal).
inherits(dog,animal).
inherits(dachshund, dog).
inherits(toy,object).
inherits(ball,object).
inherits(post,object).
inherits(ball,toy).
inherits(post,toy).
% definitions of interface implementation
implements(cat,imeow).
implements(dog,iwoof).
% definitions of objects (instances of classes)
instance(fluffy,cat).
instance(fido,dog).
instance(rex,dog).
instance(schnitzel,dachshund).
instance(superscratch,post).
instance(bouncyball,ball).
instance(tennisball,ball).
% definitions of behavior
playswith(cat,post).
playswith(dog,ball).
% definitions of superclasses
superclass(C,D) :- inherits(C,D).
superclass(D,C) :- inherits(D,X), superclass(X,C).
% definitions of subclasses
subclass(C,D) :- superclass(X,D), inherits(C,X).
我需要的输出是
?- subclass(toy,X).
X = ball ;
X = post ;
false.
但我明白了
错误的。
这是痕迹。
?- trace, subclass(toy,X).
Call: (7) subclass(toy, _G246) ? creep
Call: (8) inherits(toy, _G366) ? creep
Exit: (8) inherits(toy, object) ? creep
Call: (8) superclass(object, _G246) ? creep
Call: (9) inherits(object, _G246) ? creep
Fail: (9) inherits(object, _G246) ? creep
Redo: (8) superclass(object, _G246) ? creep
Call: (9) inherits(object, _G366) ? creep
Fail: (9) inherits(object, _G366) ? creep
Fail: (8) superclass(object, _G246) ? creep
Fail: (7) subclass(toy, _G246) ? creep
false.