Previous: , Up: compensations   [Contents][Index]


7.2 Compensations API

The compensations mechanism is built on top of the unwind protection mechanism:

Syntax: with-compensations ?body0 ?body

Allocate a new compensations stack, then evaluate all the ?body forms in the given order. If no error occurs: call run-compensations, reset the compensations stack to empty, finally return the result values of the last ?body form.

If the dynamic extent of the evaluation of the ?body forms is terminated: the accumulated compensations are evaluated in reverse order.

Syntax: with-compensations/on-error ?body0 ?body

Allocate a new compensations stack, then evaluate all the ?body forms in the given order. If no error occurs: reset the compensations stack to empty, return the result values of the last ?body form.

If the dynamic extent of the evaluation of the ?body forms is terminated by escaping from the body directly or by escaping from the body while handling a raised a exception: the accumulated compensations are evaluated in reverse order.

Function: run-compensations

Evaluate all the compensation thunks in the current stack, in last in/first out order; compensation thunks are called in the current dynamic environment. If a compensation thunk raises an exception: the exception is blocked and silently discarded.

This function should be called only inside the dynamic environment prepared by with-compensations and similar syntaxes. It can be called multiple times: every time the compensation thunks are consumed and removed from the stack.

Syntax: with-compensation-handler ?release-thunk ?alloc-thunk

First push ?release-thunk on the current compensations stack, then evaluate ?alloc-thunk. Return the results of evaluating ?alloc-thunk.

Syntax: compensate ?alloc0 ?alloc … (with ?release0 ?release …)
Auxiliary Syntax: with

First evaluate all the ?alloc expressions then, only if they perform a normal return: push one thunk holding all the ?release forms on the current compensations stack. Return the result of the last ?alloc expression.

The auxiliary syntax with is matches with its symbol name.

Syntax: push-compensation ?release0 ?release

Push a thunk holding the ?release forms on the current compensations stack.

Function: push-compensation-thunk thunk

Push the given thunk on the current compensations stack.


Previous: , Up: compensations   [Contents][Index]

This document describes version 0.1.0-devel.1 of MMCK Exceptional Conditions.