Operators
Combined with term expansion (§33), operators let you build readable domain-specific languages.
14.1 Operators are syntax for terms
?- X = 1 + 2 * 3, X =.. L. % L = [+, 1, 2*3]
?- display(a + b * c). % +(a,*(b,c))14.2 Defining operators: op(Priority, Type, Name)
Priority: 1–1200 (higher binds more loosely; :- is 1200, , is 1000, + is 500, * is 400).
Type: xfx (non-assoc infix), xfy (right-assoc), yfx (left-assoc), fy/fx (prefix), xf/yf (postfix).
:- op(700, xfx, is_bigger_than).
:- op(200, xfy, likes).
:- op(900, fy, not).
:- op(100, xf, is_dead).
elephant is_bigger_than mouse.
john likes mary.
butterfly is_dead.
?- X is_bigger_than mouse. % X = elephant
?- current_op(P, T, +). % query existing operators14.3 Standard operator table (ISO + common)
= \= == \== @< @> @=< @>= =.. is =:= =\= < > =< >= >:< :< as + - /\ \/ xor
* / // mod rem << >> div rdiv divmod
14.4 Operators for DSLs
Combined with term expansion (§33), operators let you build readable domain-specific languages.
:- op(800, xfx, ===>).
rule(if_raining ===> take_umbrella).