In Prolog, custom operators can be defined using op/3
:
op(+Precedence, +Type, :Operator)
Declares Operator to be an operator of a Type with a Precedence. Operator can also be a list of names in which case all elements of the list are declared to be identical operators.
Precedence is an integer between 0 and 1200, where 0 removes the declaration.
Type is one of: xf
, yf
, xfx
, xfy
, yfx
, fy
or fx
where f
indicates the position of the functor and x
and y
indicate the positions of the arguments. y
denotes a term with a precedence lower or equal to the precedence of the functor, whereas x
denotes a strictly lower precedence.
fx
, fy
xfx
(not associative), xfy
(right associative), yfx
(left associative)xf
, yf
Example usage:
:- op(900, xf, is_true).
X_0 is_true :-
X_0.
Example query:
?- dif(X, a) is_true.
dif(X, a).