Previous: Function Overloading To the Table of Content Next: User Defined Reader Procedure

- 2.2.16 -
TMT Pascal Language Description
Pascal Language Structure

User Defined Operators

TMT Pascal allows redefining of the standard operators on predefined types and overloading of these operators for new types. For this, it uses the construction
  overload
The syntax is:
  overload op_sign = qualified procedure identifier;
Where the op_sign is one of the standard operator symbols:
  + - / * = <> < > <= >=
  and or xor shl shr mod div in not
  +:=   -:=   *:=   /:=
When a re-defined operator is used, TMT Pascal uses the last definition that could be applied toward operands of given types.
For example, this fragment:
function add2_rr (a, b: Real): Real;
  Result := (a + b) * 2;
function add2_ii (a, b: Integer): Integer;
  Result := (a + b) * 2;
overload + = add_rr;
overload + = add_ii;
redefines the "+" operator. Notice that the order of overload's is important.
The reverse order
overload + = add_ii;
overload + = add_rr;
will cause add_rr to be used always since integers can always be cast into reals.

In the SOURCES subdirectory you can find the source of the COMP module which realizes the complex numbers and defines the operators on them.

Remarks:


Previous: Function Overloading To the Table of Content Next: User Defined Reader Procedure
Function Overloading Table of Content User Defined Reader Procedure

- 2.2.16 -