11.3.147 op/3 [ISO]

Synopsis

op(+Precedence, +Type, +Name)

declares Name to be an operator of the stated Type and Precedence.

Arguments

Precedence
integer, must be nonvar and in the range 1-1200
Type
one of [xfx,xfy,yfx,fx,fy,xf,yf], must be nonvar
Name
atom or list of atom, must be ground

Description

Operators are a notational convenience to read and write Prolog terms. You can define new operators using op/3.

The Precedence of an operator is used to disambiguate the way terms are parsed. The general rule is that the operator with the highest precedence is the principal functor.

The Type of an operator decides the position of an operator and its associativity. In the atom that represents the type the character ‘f’ represents the position of the operator. For example, a type ‘fx’ says that the operator is a prefix operator. The character ‘y’ indicates that the operator is associative in that direction. For example, an operator of type ‘xfy’ is a right-associative, infix operator.

To cancel the operator properties of Name (if any) set Precedence to 0.

Exceptions

instantiation_error
An argument is not ground
type_error
Precedence is not an integer or Type is not an integer or an operator is not an atom
domain_error
Precedence is not in the range 1-1200, or Type is invalid,
permission_error
Attempt to redefine the operator ','

See Also

current_op/3, ref-syn-ops.


Send feedback on this subject.