Search code examples
syntaxprologoperatorsiso-prolog

Why are round brackets not needed for atoms that are high priority operators?


In older textbooks1 one frequently encounters operator declarations like the following:

?- op(1200,fx,(:-)).
              ^  ^

These round brackets used to be necessary. But today, they are no longer needed:

| ?- writeq(op(1200,fx,(:-))).     
op(1200,fx,:-)

Why are they no longer needed? How does the standard cope with this situation?


1 p.97 6. Standard Operator Declarations of MU-Prolog 3.2db reference manual, appearing in Negation and Control in Prolog by Lee Naish, LNCS 238, Springer-Verlag 1985.


Solution

  • op(1200,fx,:-) is a compound term in functional notation.

    Quoting 6.3.3 Compound terms --- functional notation:

    A compound term written in functional notation has the form f(A1,...,An) where each argument Ai is an arg and they are separated by , (comma).

    term = atom, open ct, arg list, close;

    arg list = arg;
    arg list = arg, comma, arg list;

    Quoting 6.3.3.1 Arguments:

    An argument (represented by arg in the syntax rules) occurs as the argument of a compound term or element of a list. It can be an atom which is an operator, or a term with priority not greater than 999.

    arg = atom; if atom is an operator (with arbitrary priority)
    arg = term; (with priority 999)

    Due to above highlighted case arg = atom;, :- does not need round brackets in op(1200,fx,:-).

    If it were not for above special case, we would need round brackets, as the derivation would have to follow 6.3.1.3 Atoms:

    term = atom; with priority 0, if atom is not an operator
    term = atom; with priority 1201, if atom is an operator.