Previous: 2.2.15. Overloaded Functions To the Table of Contents Next: 2.2.17. User Defined Reader Procedure
2.2.15. Overloaded Functions Table of Contents 2.2.17. User Defined Reader Procedure

- 2.2.16. -
Table of Contents
2. TMT Pascal Language Description
2.2. Pascal Language Structure
2.2.16. User Defined Operators


2.2.16. 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: 2.2.15. Overloaded Functions To the Table of Contents Next: 2.2.17. User Defined Reader Procedure
2.2.15. Overloaded Functions Table of Contents 2.2.17. User Defined Reader Procedure

- 2.2.16. -