【发布时间】:2014-11-24 17:06:52
【问题描述】:
取一个给定的数据库,例如
input(80).
input(30).
input(25).
input(90).
计算超过 50 乘以 100 的输入量,限制为仅采用 /1 输入。 例如
%compute(?integer).
compute(I).
I = 200 %seeing as input(80) and input(90) matches the condition of being above 50
我尝试了以下 prolog 代码来模仿计算功能,但未成功:
compute(I) :- input(G), G>50, I is I+100.
I+100 没有按我的意愿工作。
【问题讨论】:
-
您的
compute不起作用,因为逻辑表明,如果G是输入、G > 50和I is I + 100,*compute(I)为真。I没有初始值,如果有,则第一次成功一次G > 50。您真的想要聚合所有可能的值,这可以使用findall来完成。
标签: prolog logic logic-programming