In fact, succ/2 is made to order for natural numbers.
- What is the predecessor of 0:
succ(X,0)... fails, "there is nothing like that" - What is the predecessor of -1:
succ(X,-1)... throws: "What the hell is this -1?" - What is the successor of -1:
succ(-1,X)... throws: "What the hell is this -1?"
There should be an
zsucc(?A,?B)
working on ℤ, not only on ℕ.
zsucc(X,Y) :-
(nonvar(X) -> (integer(X) -> true ; type_error(integer,X)) ; true),
(nonvar(Y) -> (integer(Y) -> true ; type_error(integer,Y)) ; true),
((var(X),var(Y)) -> instantiation_error("Need at least one value instantiated") ; true),
(nonvar(X)
-> Y is X+1
; X is Y-1).