Sunday, December 3, 2017

Proper Tail Calls, CPS, Trampolines

Proper Tail Calls allows us to run a program with recursive calls without blowing up stack memory.  Tail calls are functions which can be executed without growing stack.

In addition to having proper tail calls, we can implement TCO - Tail Call Optimizations to improve performance of tail recursive functions.

Continuation Passing Style can be used for advanced recursion.

Using Trampolines, we will be calling functions one by one and can get around limitations of having no PTC support. A Trampoline expects a continuation function and executes the same whenever it gets one.

Further Reading
http://lucasfcosta.com/2017/05/08/All-About-Recursion-PTC-TCO-and-STC-in-JavaScript.html
frontendmasters.com
http://www.datchley.name/recursion-tail-calls-and-trampolines/

No comments:

Post a Comment