Continuations act as "functional accumulators". The
basic idea is to implement a function
f by defining a
f' that takes an additional
argument, called the continuation. This continuation is a
function; it encapsulates the computation that should be done on the
f. In the base case, instead of
returning a result, one calls the continuation. In the recursive
case, one augments the given continuation with whatever computation
should be done on the result.
Continuations can be used to advantage for programming solutions to a variety of problems. In today's lecture we looked at two examples. First, we implemented a function for summing the integers in a list using continuations (and compareed that to other possible implementations). We also looked at an example in which continuations may be used to efficiently manage evaluations, short-circuiting unnecessary computations. Next time we will look at the use of continuations in backtracking search.