[ ECLiPSe Prolog Environment built-in.|Group Index| Full Index]

op(+Precedence, +Associativity, +Name)

Defines the operator(s) Name with precedence Precedence and associativity Associativity locally in the current module. Defining a local operator of precedence 0 hides a global operator of the same associativity group (postfix, infix or prefix).

+Precedence
Integer.
+Associativity
Atom.
+Name
Atom or List of atoms.

Description

Defines Name as an operator of precedence Precedence and associativity Associativity. Name may be a single operator or a list of operators, in which case each is given the specified precedence and associativity.

The operator is defined to be local to the current module only.

Precedence is an integer in the range 0 to 1200.

Associativity must be one of the following atoms:

----------------------------
 xfx           infix
 xfy           infix
 yfx           infix
 fx            prefix
 fy            prefix
 xf            postfix
 yf            postfix
x represents an argument whose precedence must be lower than that of the operator. y represents an argument whose precedence must be lower or equal to that of the operator.

Prefix, infix and postfix operators are independent of each other and may coexist. See the manual chapter on syntax about how ambiguities are resolved in this case.

A precedence of 0 has a special meaning. It erases a local operator definition and/or hides a global operator of the same name and associativity class. A local operator definition can be completely removed with abolish_op/2. In this case, a global operator (if any) of the same name becomes visible again.

Fail Conditions

None.

Resatisfiable

No.

Exceptions

(4) Instantiation fault
Any of the input arguments is uninstantiated.
(5) Type error
Precedence is not an integer.
(5) Type error
Name is not an atom or list of atoms.
(5) Type error
Associativity is not an atom.
(6) Range error
Precedence is not in range 0 to 1200.
(6) Range error
Associativity is not one of xf, xfx, fy, etc.

Examples


Success:
      [eclipse]: module(a).
      [a]: current_op(X, Y, +).    % there are two global operators
      X = 500
      Y = yfx     More? (;)
      X = 500
      Y = fx     More? (;)
      no (more) solution.
      [a]: display(a+b*c).
      +(a, *(b, c))
      yes.
      [a]: op(100, xfy, +).        % define a local infix
      yes.
      [a]: display(a+b*c).
      *(+(a, b), c)
      yes.
      [a]: abolish_op(+, xfy).     % remove the local infix
      yes.
      [a]: display(a+b*c).
      +(a, *(b, c))
      yes.
      [a]: op(0, xfy, +).          % just hide the global infix
      yes.
      [a]: current_op(X, Y, +).
      X = 500
      Y = fx     More? (;)
      no (more) solution.

Error:
      op(X, fx, aaa).             (Error 4).
      op(a, fx, aaa).             (Error 5).
      op(100, xfx, 1).            (Error 5).
      op(100, abc, fred).         (Error 6).
      op(100, xfx, aaa),
          op(100,xf,aaa).         (Error 43).


See Also

abolish_op / 2, current_op / 3, global / 1, local / 1