Go to the first, previous, next, last section, table of contents.

Continuations

Scheme has the usual control constructs that most languages have--conditionals (if statements), loops, and recursion--but it also has a very special control structure called call-with-current-continuation.

(Warning: call-with-current-continuation is weird.)

call-with-current-continuation allows you to save the state of a computation, package it up as a data structure, and go off and do something else. Whenever you want, you can restore the old saved state, abandoning the current computation and and picking up where the saved computation left off.

This is far more powerful than normal procedure calling and returning, and allows you to implement advanced control structures such as backtracking, cooperative multitasking, and custom exception-handling.

You won't use call-with-current-continuation most of the time, because more conventional control structures are usually sufficient. But if you need to customize Scheme with a special control structure to solve a particular kind of problem, you can do it with call-with-current-continuation.

==================================================================
This is the end of Hunk O.

TIME TO TRY IT OUT

At this point, you should go read Hunk P of the next chapter
and work through the examples using a running Scheme system.
Then return here and resume this chapter.
==================================================================

(Go to Hunk P, which starts at section Basic Programming Examples (Hunk P).)


Go to the first, previous, next, last section, table of contents.