Sometimes  it  is convenient to write certain functors as operators - 2-ary
functors may be declared as infix operators and 1-ary functors as prefix or
postfix operators.  Thus it is possible to write, eg.

                        X+Y     (P;Q)     X<Y +X     P;

as instead of:-

                      +(X,Y)   ;(P,Q)   <(X,Y) +(X)   ;(P)

The use of operators is described fully in Section 1.4.

The  Prolog syntax caters for operators of three main kinds - infix, prefix
and  postfix.   Each operator has a precedence, which is a number from 1 to
1200.   The  precedence  is  used  to  disambiguate  expressions  where the
structure  of  the  term  denoted  is  not made explicit through the use of
brackets.   The  general  rule, in an otherwise ambiguous subexpression, is
that  it  is the operator with the HIGHEST precedence that is the principal
functor.  Thus if '+' has a higher precedence than '/', then

                               a+b/c     a+(b/c)

are equivalent.  Brackets are necessary if you wish to write:

                                    (a+b)/c

If  there  are  two  operators in the subexpression having the same highest
precedence, the ambiguity must be resolved from the types of the operators.
The possible types for an infix operator are:-

                              xfx     xfy     yfx

With  an  operator  of type 'xfx', it is a requirement that both of the two
subexpressions  which  are  the  arguments of the operator must be of LOWER
precedence  than the operator itself, ie.  their principal functors must be
of  lower  precedence,  unless  the  subexpression  is explicitly bracketed
(which gives it zero precedence).  With an operator of type 'xfy', only the
first  or  left-hand  subexpression must be of lower precedence; the second
can  be  of the SAME precedence as the main operator; and vice versa for an
operator of type 'yfx'.

For  example,  if the operators '+' and '-' both have type 'yfx' and are of
the same precedence, then the expression:-

                                   a - b + c
is valid, and means:-

                                    (a-b)+c

Note  that the expression would be invalid if the operators had type 'xfx',
and would mean:-

                                    a-(b+c)

if the types were both 'xfy'.

The possible types for a prefix operator are:-

                                    fx    fy

and for a postfix operator they are:-

                                    xf    yf

The  meaning  of  the types should be clear by analogy with those for infix
operators.   As  an  example,  if '-' were declared as a prefix operator of
type 'fy', then:-
                                     - - P

would  be  permissible.   If  the  type were 'fx', the preceding expression
would not be legal, although:-

                                      - P

would still be permissible.

In  UNSW  Prolog,  a  functor named name is declared as an operator of type
type and precedence precedence by the command:-

                          op(precedence, type, name)!

The argument name can also be a list of names of operators of the same type
and precedence.

It  is possible to have more than one operator of the same name, so long as
they are of different kinds, ie.  infix, prefix or postfix.  An operator of
any  kind  may  be  redefined  by a new declaration of the same kind.  This
applies equally to operators which are provided as standard in UNSW Prolog,
namely:-

     :- op(700,xfx,[=,==,/=,is,<,>,=<,>=]).
     :- op(500, yfx, [+, -]).
     :- op(500,  fx, [+,-]).
     :- op(400, yfx, [*, /]).
     :- op(300, xfx, mod).


Note  also that the arguments of a compound term written in standard syntax
must  be  expressions  of  precedence  BELOW 1000.  Thus it is necessary to
bracket the expression 'P:-Q' in:-

                                 assert((P:-Q))



Note  carefully  the  following  syntax restrictions, which serve to remove
potential  ambiguity  associated  with  prefix  operators.   (1)  In a term
written  in  standard  syntax,  the principal functor and its following '('
must NOT be separated by any intervening spaces, newlines etc.  Thus:-

                                 point (X,Y,Z)
is invalid syntax.

(2)  If  the argument of a prefix operator starts with a '(', this '(' must
be separated from the operator by at least one space or other non-printable
character.  Thus:-

                                 :-(p | q) , r.

is invalid syntax, and must be written as eg.

                                :- (p | q) , r.

(3)  If  a  prefix  operator is written without an argument, as an ordinary
atom,  the  atom  is treated as an expression of the same precedence as the
prefix operator, and must therefore be bracketed where necessary.  Thus the
brackets are necessary in:-

                                    X = (?)
