2012-05-25 00:39:25 -07:00
|
|
|
pure fn range(from: uint, to: uint, f: fn(uint) -> bool) {
|
|
|
|
let mut i = from;
|
|
|
|
while i < to {
|
2012-08-01 17:30:05 -07:00
|
|
|
if !f(i) {return;} // Note: legal to call argument, even if it is not pure.
|
2012-05-25 00:39:25 -07:00
|
|
|
i += 1u;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pure fn range2(from: uint, to: uint, f: fn(uint)) {
|
2012-06-30 16:19:07 -07:00
|
|
|
for range(from, to) |i| {
|
2012-05-25 00:39:25 -07:00
|
|
|
f(i*2u);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pure fn range3(from: uint, to: uint, f: {x: fn(uint)}) {
|
2012-06-30 16:19:07 -07:00
|
|
|
for range(from, to) |i| {
|
2012-06-30 12:23:59 +01:00
|
|
|
f.x(i*2u); //~ ERROR access to impure function prohibited
|
2012-05-25 00:39:25 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|