racket/collects/honu/examples/old/List-main.honu
Stevie Strickland 7dbb99d3c6 merged 292:296 from branches/sstrickl
svn: r297
2005-07-02 04:03:02 +00:00

25 lines
683 B
Plaintext

List iota(int n) {
List ret = new MTList : List();
while(n > 0) {
ret = new ConsList : List(car = new Int : IInt(value = n), cdr = ret);
n = n - 1;
};
return ret;
}
int main() {
List x = iota(100);
List y = x.map(fun(Any x) {
if(x isa IInt) {
new Int : IInt(value = (x : IInt).value * 2);
} else {
x;
};
});
(y.foldl(fun(Any x, Any i) {
if x isa IInt && i isa IInt {
new Int : IInt(value = (x : IInt).value + (i : IInt).value);
} else { i; } ;
}, new Int : IInt(value = 0)) : IInt).value;
}