背景
我需要编写一个关系 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不为零”?
编辑该列表是整数列表。