projog

3.89. arithmetic_function(X) - defines a predicate as an arithmetic function.

Allows the predicate defined by X to be used as an arithmetic function.

Examples

squared(X,Y) :- Y is X * X.

?- squared(3,X).
X = 9

yes

?- X is squared(3).

Cannot find arithmetic operator: squared/1

?- arithmetic_function(squared/1).

yes

?- X is squared(3).
X = 9

yes

always_fails(X, Y) :- fail.

?- arithmetic_function(always_fails/1).

yes

?- X is always_fails(3).

Could not evaluate: always_fails/2 for: always_fails(3)