previous up next     contents index
Next: Dynamic Wind Up: Control Flow Previous: Control Flow

Continuations

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

 
   (let/cc k expr  tex2html_wrap_inline8724 ) 
    tex2html_wrap_inline8824  
   (call/cc (lambda (k) expr  tex2html_wrap_inline8724 )) 
A continuation can only be invoked from the thread (see section 2.14) in which it was captured. Multiple return values can be passed to a continuation (see section 2.26).

          In addition to regular call/cc, MzScheme provides call-with-escaping-continuation (or call/ec) and catch (or let/ec). A continuation obtained from call/ec or catch can only be used to escape from the expression; i.e., the continuation is only valid until the call/ec or catch expression returns a value. 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 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 scope.



PLT