December 2021
Beginner
840 pages
47h 29m
English
We can make all function calls tail calls by first encapsulating any computation remaining after each call—the “what to do next”—into an explicit, reified continuation and then passing that continuation as an extra argument in each tail call. In other words, we can make the implicit continuation of each called function explicit by packaging it as an additional argument passed in each function call. This approach is called continuation-passing style (CPS), as opposed to direct style. We begin by presenting some examples to acclimate readers to the idea of passing an additional argument to each function, with that argument capturing the continuation of the call to the function. Consider the following ...