PageRenderTime 8ms CodeModel.GetById 1ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/src/test/run-pass/tail-cps.rs

http://github.com/jruderman/rust
Rust | 19 lines | 12 code | 6 blank | 1 comment | 6 complexity | a52809ac4a9ea65555ed4691a447440a MD5 | raw file
 1
 2
 3
 4// -*- rust -*-
 5fn checktrue(rs: bool) -> bool { assert (rs); return true; }
 6
 7fn main() { let k = checktrue; evenk(42, k); oddk(45, k); }
 8
 9fn evenk(n: int, k: extern fn(bool) -> bool) -> bool {
10    debug!{"evenk"};
11    log(debug, n);
12    if n == 0 { return k(true); } else { return oddk(n - 1, k); }
13}
14
15fn oddk(n: int, k: extern fn(bool) -> bool) -> bool {
16    debug!{"oddk"};
17    log(debug, n);
18    if n == 0 { return k(false); } else { return evenk(n - 1, k); }
19}