Next: iklib unwind-protect except 1, Previous: iklib unwind-protect syntaxes, Up: iklib unwind-protect [Index]
The concept of dynamic extent termination is defined by Vicare’s unwind–protection mechanism and it is not a R6RS concept. In this discussion, we consider the syntax use:
(with-unwind-protection ?unwind-handler ?thunk)
the procedure ?unwind-handler is called when the dynamic extent of
the invocation of ?thunk terminates; dynamic extent
termination is different from dynamic extent exiting
as determined by dynamic-wind
(see dynamic-wind). When the
execution flow exits the dynamic extent of a function call: such extent
might also terminate, but not all the exits are also terminations.
The dynamic extent of a call to ?thunk is terminated, and so ?unwind-handler is invoked, when:
guard
, but only when a clause of
guard
has a test expression returning non–false.
(guard (E (?test ?expr)) (with-unwind-handler ?unwind-handler ?thunk))
This is what happens:
guard
and it returns non–false.
with-unwind-protection
, and
its return values discarded.
guard
and its return values are returned to the
continuation of guard
.
break
,
continue
or return
, as defined by the library
(vicare)
, to escape from a form that encloses an
unwind–protection syntax. ?unwind-handler is applied to the
symbol ‘escape’.
As bound by the loop syntaxes while
, until
, …
and the syntax returnable
: these fluid syntaxes reinstate a
continuation at the beginning or outside of while
,
until
, … and returnable
and perform special
operations to terminate the dynamic extent of the call to ?thunk
in an unwind–protection form.
The dynamic extent of a call to ?thunk is not terminated, and so ?unwind-handler is not invoked, when:
raise-continuable
, and such call performs a normal return to
?thunk.
exit
).
yield
is
called from within ?thunk to hand control to another coroutine.
About the termination of the dynamic extent of ?thunk, we must acknowledge that:
&non-reinstatable
component
(see &non-reinstatable).
guard
intercepts it: if a test expression in a clause of
guard
raises an exception, the ?unwind-handler may not be
called.
While it is possible to raise
any object: it is better to always
raise a condition object (possibly compound), so that the test
expressions in guard
uses can just be condition object type
predicates; such predicates never raise exceptions.
If ?unwind-handler raises an exception: such exception is blocked and discarded.
Next: iklib unwind-protect except 1, Previous: iklib unwind-protect syntaxes, Up: iklib unwind-protect [Index]