![]() ![]() ![]() |
![]() |
Usage:
op(Priority, Type, Operator)
Operator definition.
Priority | Priority of the operator. Smaller numbers specify higher priority. |
Type | Type of the operator. |
Operator | Operator sign |
Operator types:
fx, fy | unary, the argument follows
e.g.: 'minus X' as -X |
xf, yf | unary, after the argument
e.g.: 'factorial N' as N! |
xfx, yfy, xfy, yfx | binary, between the arguments
e.g.: +, -, *, / |
x and y letters specify associativity:
x the main operator in the operand must be of higher priority
than this operator
y the main operator in the operand must be of higher or equal
priority than this operator
Thus yfx denotes an operator which will be evaluated from left to right (such as + or * ), and xfy denotes an operator which will be evaluated from right to left (such as ; ), and xfx denotes an operator which is not associative (it can be placed only between arguments with the main operators of higher priority) such operators are > , < and yfy denotes an operator which is right and left associative. Usually people do not use the last type because it gives double sense.
If one of the letters is repeated as xfxx the operator will be evaluated to a predicate assuming that the corresponding argument is a list of terms separated by commas. For example H:-G1,G2 will be evaluated to a :-(H, G1, G2) not as :-(H, [G1, G2]) as if it was of type xfx .
If you want to use an operator in the source then it should be defined as an axiom which is before the row where you want to use it or you can put the op operator in the body of a clause but in the second case this definition will take effect only after that this clause is executed.
The list of defined operators is available in Help/Operators. The operators
are defined after compilation.