[][src]Module idata::tc

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);



Support to call or return from a recursive function



Function to simulate TCO. See example