Content deleted Content added
m →Type system: <source lang="ada"> |
m →Expression reduction: operator overloading: <source lang="ada"> |
||
Line 139:
===Expression reduction: operator overloading===
Operators can be defined using the <code>written</code> form of function declarations. Below is the code that would declare the addition of integers:
<source lang="ada">
function Add(X, Y: integer) return integer written X+Y
</source>
Such ''written forms'' can have more than two parameters. For instance, a matrix linear transform can be written as:
<source lang="ada">
function Linear(A, B, C : matrix) return matrix written A+B*C
</source>
A written form can use constants, and such a form is more specialized than a form without constants. For example:
<source lang="ada">
function Equal(A, B : matrix) return boolean written A=B
function IsNull(A : matrix) return boolean written A=0
function IsUnity(A : matrix) return boolean written A=1
</source>
The mechanism is used to implement all basic operators. An expression is progressively reduced to function calls using written forms. For that reason, the mechanism is referred to as ''expression reduction'' rather than operator overloading.
|