In this lecture, we expanded on last lecture's discussion of the pipe operator, which lets us chain together function calls in a easy to write way.
We saw that we could write functions which instead had a property that we called cool, which was instead of having their result piped into a different function, simply have the function take in a function which the result would be applied to.
We saw that writing functions in this cool way would allow us to write recursive functions in a pipelined way, while preserving the property of tail recursion. We were able to write pipelines of data being passed between steps which explicitly named nad considered the intermediate results produced by each step of the pipeline.
It turns out that this notion of cool functions is exactly the same as something called continuation-passing style, and that the functions we passed in which accepted the results are termed continuations. Essentially, we can define functions which explicitly accept functions which they are to pass their results to.
Even more importantly than just passing data between steps of functions, we saw that CPS allows us to write functions which essentially use functional accumulators, or instead of using accumulators which are themselves the return value, they use accumulators which describe what to do with the return value.
We then covered strategies for how we might translate functions which are not written in CPS to CPS. We also saw that using CPS functions which have numerous continuations, we can write very clear code that has explicit control flow, where the decisions made by the function are encoded in the continuations that it accepts.
Slides