Next: Names Up: An introduction to the ALDOR Previous: Characteristics of the ALDOR language

## First examples

• A function definition:
```double(n: Integer): Integer == n + n
```
• An input file to be compiled:
```#include "aldor"
#include "aldorio"

macro Z == MachineInteger;

fib(n:Z):Z == {
n = 0 or n = 1 => 1;
fib(n-1) + fib(n-2);
}

import from Z;

stdout << " fib 10 = " << fib(10) << endnl;
```

• A type definition.
```ResidueClassRing(R:EuclideanDomain, p:R): Ring with {
class: R -> %;
sample: % -> R;
} == R add {
Rep == R;
import from R;

1: % == per(1);
0: % == per(0);
zero?(x:%): Boolean == zero?(rep(x));
(x:%) = (y:%) : Boolean == zero?(x-y);
one?(x:%): Boolean == x = 1;
class(a:R):% == {
(q,r) := divide(a,p);
per(r);
}
sample(x:%): R == rep(x);
(x:%) + (y:%) : % == class(rep(x) + rep(y));
-(x:%) : % == class(-rep(x));
(x:%) * (y:%) : % == class(rep(x) * rep(y));
(n:Integer) * (x:%): % == class(n * rep(x));
(x:%) ^ (n:NonNegativeInteger) : % == class(rep(x) ^ n);
recip(x:%): Partial(%) == {
import from Partial(%);
(u,v,g) := extendedEuclidean(rep(x),p);
h?: Partial(R) := recip(g);
failed? h? => failed();
h: R := retract(h?);
[class(h * u)];
}
}
```

Next: Names Up: An introduction to the ALDOR Previous: Characteristics of the ALDOR language
Marc Moreno Maza
2003-06-06