[Aldor-l] Generators
Ralf Hemmecke
ralf at hemmecke.de
Thu Nov 8 03:37:54 EST 2007
Hello Peter,
On 11/06/2007 11:52 PM, Peter Broadbery wrote:
>
> This patch should (emphasis on that word there) implement 'for (x, y) in ...'.
>
> Peter
You are a *hero*!!!
I've just applied your patch, compiled the compiler and then I could
compile and run the follwoing programs without any problem.
THANK YOU.
Ralf
PS: Now we need someone who incorporates this patch into the SVN
repository. Laurentiu?
---BEGIN aaa.as
#include "aldor"
#include "aldorio"
macro SIS == Cross(String, Integer, String);
import from Integer, String;
construct(): List SIS == {
li: List Integer := [1, 2, 3, 4];
ls: List String := ["a", "bb", "ccc"];
lis: List SIS := empty;
for a in ls repeat {
for i in li repeat {
for s in ls repeat {
lis := cons((a,i,s+s), lis);
}
}
}
lis;
}
main(): () == {
import from List SIS;
for (s, i, t) in construct() repeat {
stdout << "(" << s << ", " << i << ", " << t << ")";
stdout << newline;
}
}
main();
---END aaa.as
---BEGIN bbb.as
#include "aldor"
#include "aldorio"
Times(A: Type, B: Type): with {
*: (List A, List B) -> List Cross(A, B);
} == add {
(la: List A) * (lb: List B): List Cross(A, B) == {
z: List Cross(A, B) := empty;
la := reverse la;
lb := reverse lb;
for a in la repeat for b in lb repeat z := cons((a,b), z);
z;
}
}
main(): () == {
import from String, Integer, List String, List Integer;
import from Times(String, Integer), List Cross(String, Integer);
for (s, i) in ["a", "bb", "ccc"] * [1, 2, 3, 4] repeat {
stdout << "(" << s << ", " << i << ")" << newline;
}
lis: List Cross(Integer, String) := [
(i, s) for (s, i) in ["a", "b"] * [2, 3, 5]
];
for (i, s) in lis repeat {
stdout << "(" << i << ", " << s << ")" << newline;
}
}
main();
---END bbb.as
More information about the Aldor-l
mailing list