In order to try out Peters program I picked some code at random from the Aldor User Guide here:
http://www.aldor.org/docs/HTML/chap2.html#4Am I correct in thinking that this is the 'official' documentation for Aldor?
I happened to choose the 'MiniList' code.
I have copied the full program (+ Peters prefix) below.
When I saved the program (to compile it) it produced an error. I attempted to fix it (with my very limited experience of Aldor so my fixes may not be correct) and it produced another error and so on, here are my first few 'fixes':
-MiniList(S: BasicType): LinearAggregate(S) = add {
+MiniList(S: BasicType): LinearAggregate(S) == add {
- (l1: %) = (12: %): Boolean == {
+ (l1: %) = (l2: %): Boolean == {
- empty ? l1 and empty? l2
+ empty? l1 and empty? l2
In the end I gave up, am I doing something wrong or is the code full of typos?
Martin
The original code:
-----------------------------------------------------------
-- Include file for the aldorTest project.-- it is expected that it will be included in all source files that
-- make up this project.
--NOBUILD
#if BUILD_aldorTest
#else
#library aldorTest "libaldorTest.al"
#endif
#include "aldor"
MiniList(S: BasicType): LinearAggregate(S) = add {
Rep == Union(nil: Pointer, rec: Record(first: S, rest: %));
import from Rep, SingleInteger;
local cons (s:S,l:%):% == per(union [s, l]);
local first(l: %): S == rep(l).rec.first;
local rest (l: %): % == rep(1).rec.rest;
empty (): % == per(union nil);
empty?(l: %):Boolean == rep(1) case nil;
sample: % == empty();
[t: Tuple S]: % == {
l := empty();
for i in length t..1 by -1 repeat
l := cons(element(t, i), l);
l
}
[g: Generator S]: % == {
r := empty(); for s in g repeat r := cons(s, r);
l := empty(); for s in r repeat l := cons(s, l);
l
}
generator(l: %): Generator S == generate {
while not empty? l repeat {
yield first l; l := rest l
}
}
apply(l: %, i: SingleInteger): S == {
while not empty? l and i > 1 repeat
(l, i) := (rest l, i-1);
empty? l or i ~= 1 => error "No such element";
first l
}
(l1: %) = (12: %): Boolean == {
while not empty? l1 and not empty? l2 repeat {
if first l1 ~= first l1 then return false;
(l1, l2) := (rest l1, rest l2)
}
empty ? l1 and empty? l2
}
(out: TextWriter) << (l: %): TextWriter == {
empty? l => out << "[]";
out << "[" << first l;
for s in rest l repeat out << ", " < s;
out << "]"
}
}