What it is: Wikipedia Entry on Tail Calls
With tail call optimization you can replace looping with recursion.
Rules for today:
- Functions can not have side effects
- Functions should return only one value
- No mutating state: use only basic data types and those provided in data_structures.rb
- No looping allowed. Rely on recursion instead.
These excersizes:
- Make the test files pass.
- Run the test files that don't end in "tr" using normal ruby.
- Run the test files that do end in tr using the file run_with_tail_call_optimization.rb.
The best order to attempt these:
- ruby test_fibonacci.rb
- ruby run_with_tail_call_optimization.rb test_fibonacci_tr.rb
- ruby test_todo.rb
- ruby run_with_tail_call_optimization.rb test_todo_tr.rb