[top] [up] [next]

Operators


An operator is an atom that binds several operands, just like a structure except that an operator can be prefix, infix or postfix. A prefix operator is placed before a single operand, an infix operator is placed between two operands and a postfix operator is placed after a single operand. Operators have two more properties that distinguish them from structures, each operator has a precedence and a type of associativity.
The precedence number is a number between 1 and 1200 (inclusive) and determines how strong an operator binds its arguments. The lower the precedence number the stronger the operator binds.
Associativity is determined by one of the following atoms: xf, yf, xfx, xfy, yfx, fx and fy. The meaning of these atoms are:  

Specifier Class Associatively
fx prefix non-associative
fy prefix right-associative
xfx infix non-associative
xfy infix right-associative
yfx infix left-associative
xf postfix non-associative
yf postfix left-associative

The subtract operator is left-associative because in case of two subtract operators placed after each other the left one is executed first. For instance the expression 12-6-3 is interpreted as ((12-6) - 3) because '-' is defined as an yfx operator.

The initial state of the operator table is fixed. It may however be updated with the built-in predicate op/3. The initial state is of the standard Prolog operator table is shown below:  

Priority Specifier Operator(s)
1200 xfx :- -->
1200 fx :-
1100 xfy ;
1050 xfy ->
1000 xfy ,
900 fy \+
700 xfx = \=
700 xfx == \== @< @=< @> @>=
700 xfx =..
700 xfx is =:= =\= < =< > >=
500 yfx + - /\ \/
400 yfx * / // rem mod << >>
200 xfx **
200 xfy ^
200 fy - \

The differences between the operator table defined the standard of the Prolog language and in Trinc-Prolog are stated below:

Priority Specifier Operator(s)
1000 xfy |
900 fy not
700 xfx is_string
600 yfx &
200 fy +

Several more operators are defined for the Prolog extensions, see object-oriented prolog.

[top] [up] [next]

 

info@trinc-prolog.com