We will illustrate with an infix operator and/2 and another or/2. We will choose the precedence of and/2 to be greater than that of or/2. This means that we interpret:
she is clever and rich or healthyas
Since and/2 reminds us of ,/2 we will give it the same precedence and associativity:
The required command is
op(1000,xfy,and).The predicate op/3 takes a precedence as its first argument, a legal associativity for its second argument and an operator name for its third argument. If given legal arguments, it succeeds with the side-effect of adding or changing an operator definition. You can even change the existing definitions ---but, be warned, this can be dangerous.
We could also make it like ,/2 by defining and/2 as in:
X and Y :-Note that we have to have defined and/2 as an operator before we can write the head of this clause as X and Y.call(X),
call(Y).
For or/2 we choose precedence of 950 (less than and/2) and associativity of xfy (the same as and/2) with:
op(950,xfy,or)and define it as equivalent to:
X or Y :-call(X).
X or Y :-
call(Y).