[previous] [up] [next]     [contents] [index]
Next: Dynamic Wind Up: Exceptions and Control Flow Previous: Inferred Value Names

Continuations

MzScheme supports fully re-entrant call-with-current-continuation (or call/cc). The macro let/cc binds a variable to the continuation in an immediate body of expressions:

  (let/cc k expr  tex2html_wrap_inline12552 ) 
   tex2html_wrap_inline12616 
  (call/cc (lambda (k) expr  tex2html_wrap_inline12552 )) 
A continuation can only be invoked from the thread (see section 9.1) in which it was captured. Multiple return values can be passed to a continuation (see Chapter 2).

In addition to regular call/cc, MzScheme provides call-with-escaping-continuation (or call/ec) and let/ec. A continuation obtained from call/ec can only be used to escape back to the continuation; i.e., an escaping continuation is only valid when the current continuation is an extension of the escaping continuation. The application of call/ec's argument is not a tail call.

Escaping continuations are provided for two reasons: 1) they are significantly cheaper than full continuations; and 2) full continuations are not allowed to cross certain boundaries (e.g., error handling) that escaping continuations can safely cross.

The exn:misc:continuation exception is raised when a continuation is applied by the wrong thread, a continuation application would violate a continuation boundary, or an escaping continuation is applied outside of its dynamic scope.



PLT