Kick Forward
Cristina Videira Lopes · 2020
The continuation-passing style is often used with anonymous functions (aka lambdas) as continuations, rather than with named functions. The example here uses named functions for readability. The example program uses the same kind of decomposition that we have seen in previous styles, specifically the Pipeline style, so there is no need to repeat the explanation of the purpose of each function. What is noteworthy is the extra parameter seen in all of those functions, func, and how it is used: func is the next function after the current function finishes. Let’s compare this program with the program written in the Pipeline style. This style can be used for different purposes. One of those purposes is compiler optimizations: some compilers transform the programs they compile into an intermediate representation that uses this style, so they can optimize for tail calls.