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

405 views Asked by At

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.

2

There are 2 answers

0
repeat On BEST ANSWER

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.


0
repeat On

All of the following refers to ISO/IEC 13211-1:1995. Let me move inside out...

6.5.1     graphic char       = ":";
          graphic char       = "-";

6.4.2     graphic token char = graphic char;

          graphic token      = graphic token char, { graphic token char };

          name token         = graphic token;

6.4       name               = [ layout text sequence (* 6.4.1 *) ], name token;

6.3.1.3   atom               = name;

6.5.3     open  char         = "(";
          close char         = ")";
          comma char         = ",";

6.4.8     open  token        = open  char; 
          close token        = close char;
          comma token        = comma char;

6.4.1     (* grammar rules for layout text sequence were omitted *)

6.4       comma              = comma token;
          open ct            = open  token;
          close              = [ layout text sequence ], close token;

6.3.3.1   arg                = atom; (* if that atom is an operator *)
          arg                = term; (* otherwise: priority = 999   *)

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

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

So we come back to the initial question:

These round brackets used to be necessary. But today, they are no longer needed. Why are they no longer needed? How does the standard cope with this situation?

Let's assume T = op(1200,fx,:-) holds.

  1. T is a compound term provided in functional notation.

  2. T is covered by above rule term = atom, open ct, arg list, close;

  3. atom matches op, which is the functor of T.

  4. open ct matches an open bracket.

  5. the "middle part" (the arguments of T) is covered by the grammar rules for arg list.

  6. arg list is a non-empty list of arg.

  7. What's arg?

    • a term with priority less than 1000, the priority of (',')/2. E.g., 1200 and fx.

    • an atom that is an operator. (No strings attached!)

  8. close matches a closing bracket.

Quoting:

An argument (represented by arg in the syntax rules occurs as the argument of a compount term or element of a list. It can be an atom which is an operator,or a term with priority not greater than 999. When an argument is an arbitrary term, its priority shall be less than the priority of the ',' (comma) operator so that there is no conflict between comma as an infix operator and comma as an argument or list element separator.

Note:

This concept of an "argument" ensures that both the terms f(x,y) and f(:-, ;, [:-, :-|:-]) are syntactically valid whatever operator definitions are currently defined. Comma is not an atom and the following "terms" have syntax errors: f(,,a), [a,,|v], and [a,b|,]; but the following two terms are syntactically valid: f(',',a), [a,','|v], and [a,b|','].