SWI prolog-为什么我得到了错误的答案?

时间:2014-12-28 08:31:54

标签: prolog

我在SWI Prolog中有一个简单的代码。我已经仔细编写了以下代码。当我问一些简单的问题,例如"可以甜心鱼吗?"或者" Fodor可以游泳吗?",我得到了错误的答案。任何人都可以告诉我我犯了什么错误,我已经尝试了一切。谢谢

(编辑我的代码的快捷方式:http://swish.swi-prolog.org/p/zxufyDOz.pl

motion(x,biped).
motion(x,quadruped).

spider(lobby). %Lobby is a spider
spider(x):- not(mammal(x)). %For all x, if x is a spider then x is NOT a mammal.  (Spiders are not mammals)

dog(fidora). %Fidora is a dog

fish(sweety). %Sweety is a fish
swim(x,canswim) :- fish(x).

%fish(x) :- swim(x). %For all x, if x is a fish then it can swim
%fish(x) :- not(mammal(x)). %fishes are not mammals

not(fish(x)) :- not(swim(x)). %For all x, if x is a not fish then it can’t swim

mammal(x) :- birth(x, baby). %For all x, if x is a mammal then x lays eggs or babies
mammal(x):- motion(x, biped); motion(x, quadruped). %For all x, if x is a mammal then it is either biped or quadruped

mammal(x):- dog(x). %all dogs are mammals 
mammal(x) :- platypus(x). %platypus is a mammal

birth(platypus, egg). %At least one mammal lays eggs

1 个答案:

答案 0 :(得分:0)

首先,你可以发布确切的查询,你得到错误的答案吗?例如,你的意思是“可以吃一条鱼吗?”

其次,我注意到与swim谓词的arity不一致。看看:

swim(x,canswim) :- fish(x).
not(fish(x)) :- not(swim(x)).

Mabye你的意思是:

swim(x) :- fish(x).