op(@integer, @operator_specifier, @atom_or_atom_list) [ISO]

This predicate updates the operator table used for inputting and outputting terms. The operator table specifies which atoms are regarded as operators while compiling. The first argument is used for specifying the precedence of an operator, this is a number in the range of [0, 1200].
The precedence determines how strong an operator binds to it's operands. The second argument is the operator specifier, the value of this argument must be one of the following atoms: fx, fy, xfx, yfx, xfy, xf or yf. The third argument specifies the atom to be treated as an operator, a list of atoms may also be specified.

It is possible to have a prefix or a postfix and an infix operator definition for the same operator, however it is not possible to have a prefix and a postfix definition for the same operator simultaneously.

If the precedence specified is 0 and there is an operator with the same specifier and name then that operator is removed from the operator table. If the same operator specifier and name are specified but a different precedence number than the precedence of the operator is updated.

Remarks: recompiling a module that defines new operators can cause syntax errors because the new operators are still defined. After a Prolog program stops then any new operators are still defined!

see also: always/2 char_conversion/2 current_char_conversion/2 current_op/3 operators read/1 read/2 read_term/2 read_term/3 write/1 write/2 write_canonical/1 write_canonical/2 write_list/1 write_list/2 write_list_goal/2 write_list_goal/3 write_term/2 write_term/3 writeq/1 writeq/2

Examples
op(30, xfx, ++). defines an infix operator ++ with precedence of 30
op(0, xfx, ++). removes the infix operator ++
op(100, fx, [++, --]). add two prefix operators with a precedence of 100
always( op(100, xfx, ++), op(0, xfx, ++)). define the operator infix ++ operator, and remove the same infix operator if always/2 fails

 

Exceptions
If any of the arguments is a variable then an instantiation_error exception is thrown. instantiation_error
If the priority is not a number between 0 and 1200 inclusive. domain_error(operator_priority, Priority)
Priority argument is neither a variable nor an atom type_error(integer, Priority)
Operator specifier is neither a variable nor an atom type_error(atom, Op_specifier)
An operator specifier is used that would breach the validity of the operator table permission_error(create, operator, Operator)
Operator is neither a variable nor an atom nor a list type_error(list, Operator)
An element of the operator list is neither an atom or a variable type_error(atom, Element)
Operator is ',' or an element of the operator list is ',' permission_error(modify, operator, ',')

 

 

info@trinc-prolog.com