[previous] [up] [next]     [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_inline100183 ) 
   tex2html_wrap_inline100269 
  (call/cc (lambda (k) expr  tex2html_wrap_inline100183 )) 
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-escape-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 escape continuation is only valid when the current continuation is an extension of the escape continuation. The application of call/ec's argument is not a tail call.

Escape 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 escape continuations can safely cross.

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



PLT