Assuming your argument is a list of numbers, you can simply use arithmetic operators:
power([H|T]):- H =\= 0, zero(T).
power([H|T]):- H =:= 0, power(T).
In general, you could also write \+ (H=0)
. That means, H
can not be unified with 0
.
The question is, what do you want to happen if this predicate is called with a list that is not a list of numbers. The above code would cause an error. If you want it to just fail in such cases, then it can be defined as
power([H|T]):- \+(H=0), zero(T).
power([H|T]):- H=0, power(T).