【发布时间】:2013-03-05 20:37:49
【问题描述】:
背景
我需要编写一个关系 power(P) 来查看一个列表并确定 P 中除一个元素之外的所有元素是否为零。
这是我所拥有的:
%I have a relation called zero(P) which decides if every element is zero.
power([H|T]) :- H is not zero, %The current element is non zero, the tail is all zero.
zero(T).
power([0|T]) :- power(T). %The current element is zero,
%but the tail has a non zero element in it.
一些资源建议使用剪切运算符 (!),它控制回溯,我认为这不是我想要的。
我还遇到了不可证明运算符 (\+),它似乎交换了结果(不可证明返回是),我认为这也不是我想要的。
我确实找到了Prolog Dictionary,但我不知道“not”是什么意思或如何使用它(您可以想象,Ctrl+F 会找到许多“not”的实例)。
问题
如何在序言中说“H 不为零”?
EDIT列表是整数列表。
【问题讨论】: