Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The CPS transformation is more complex when it has to deal with calls to transformed functions. To see this, let us look at turning a recursive visit into an iteration, like in Section 22.7, “Turning a Recursive Visit into an Iteration,” on page 326. For simplicity, we will visit a linked list, not a tree:
def visit(a: List[String]): String @cps[String] = {
if (a.isEmpty) "" else {
shift {
k: (Unit => String) => {
cont = k
a.head
}
}
visit(a.tail)
}
}