Next: , Previous: , Up: iklib unwind-protect   [Index]


6.9.2 Unwind–protection syntaxes

Syntax: with-unwind-handler ?unwind-handler ?thunk
Syntax: with-unwind-protection ?unwind-handler ?thunk

These two syntaxes are aliases. Call ?thunk and then, when the dynamic extent of the call terminates, call the procedure ?unwind-handler. When ?thunk performs a normal return: the return values of ?thunk become the return values of with-unwind-handler.

When called: ?unwind-handler is applied to a Scheme symbol representing the cause of the call: ‘return’, ‘escape’, ‘exception’. The argument ?unwind-handler comes before the argument ?thunk for uniformity with with-exception-handler, with-exception-handler.

Notice that a function tail–call in ?thunk is not a tail–call for with-unwind-protection.

Syntax: unwind-protect ?body ?cleanup0 ?cleanup ...

Simple wrapper for with-unwind-protection that provides a syntax similar to that of Common Lisp’s macro. It is expanded to:

(with-unwind-protection
    (lambda (dummy) ?cleanup0 ?cleanup ...)
  (lambda () ?body))