Module idata::tc [−][src]
Recursive simulation with TCO
We cannot use SSA in rust combined with a for loop
It fits fine with recursion, but...alloc
Rust doesn't have TCO (tail call optimization) in recursion.
In some cases it could be expensive and even dangerous
One option, could be to use next "trampolin"
extern crate idata; use idata::tc::*; fn main() { let (sum, _) = tail_call((0, 0), |(acc, counter)| { if counter < 101 { TailCall::Call((acc + counter, counter + 1)) } else { TailCall::Return((acc, counter)) } }); assert!(sum == 5050); }
Enums
TailCall |
Support to call or return from a recursive function |
Functions
tail_call |
Function to simulate TCO. See example |