rust/src/test/run-pass/tail-cps.rs
2012-08-23 11:14:14 -07:00

20 lines
469 B
Rust

// -*- rust -*-
fn checktrue(rs: bool) -> bool { assert (rs); return true; }
fn main() { let k = checktrue; evenk(42, k); oddk(45, k); }
fn evenk(n: int, k: extern fn(bool) -> bool) -> bool {
debug!("evenk");
log(debug, n);
if n == 0 { return k(true); } else { return oddk(n - 1, k); }
}
fn oddk(n: int, k: extern fn(bool) -> bool) -> bool {
debug!("oddk");
log(debug, n);
if n == 0 { return k(false); } else { return evenk(n - 1, k); }
}