【发布时间】:2018-05-07 22:36:58
【问题描述】:
嗨 :) Prolog 的初学者。
我有这个代码:
dog(rex).
owns(bill,rex).
animallover(X):-owns(X,Y),dog(Y).
not(beat(X,Y)):-animallover(X),isAnimal(Y).
beat(bill,tom);beat(bull,tom).
iscat(tom).
isAnimal(X):-iscat(X).
这会产生错误:No permission to modify static procedure `(;)/2'
那里有什么问题?
感谢您的帮助。
dog(rex).
owns(bill,rex).
animallover(X):-owns(X,Y),dog(Y).
notbeat(X,Y):-animallover(X),isAnimal(Y).
not(notbeat(bill,tom),notbeat(bull,tom)).
iscat(tom).
isAnimal(X):-iscat(X).
这解决了问题。但我们想回答“谁打了汤姆?”的问题
这样我们就只能问了
?- nothit(X,tom).
这将产生账单。
那么我们如何更改代码,以便我们可以知道是谁打了汤姆?
【问题讨论】:
-
您需要首先定义 hit 在此上下文中的含义。我看到了关于 is cat 和 is animal 和 dog 和 owns 甚至 notbeat的信息>。但是就这些谓词和事实而言,hit 意味着什么?就目前而言,这并没有多大意义。
-
哦,我做错了。我想问
?-notbeat(X,tom)但无论如何。这意味着,X 不会击败/击中汤姆 -
not(notbeat(bill,tom),notbeat(bull,tom)).是什么意思?
标签: prolog