Previous: dynamic environment guard, Up: dynamic environment [Index]
Let’s imagine the following prelude for all the examples in this section:
#!vicare
(import (vicare)
(only (vicare checks)
with-result
add-result))
This is what happens when we raise an exception from the in–guard thunk
of a dynamic-wind:
(with-result
(call/cc
(lambda (escape)
(with-exception-handler
(lambda (E)
(escape E))
(lambda ()
(dynamic-wind
(lambda ()
(add-result 'in-guard)
(raise 1))
(lambda ()
(add-result 'thunk))
(lambda ()
(add-result 'out-guard))))))))
⇒ (1 (in-guard))
This is what happens when we raise an exception from the out–guard
thunk of a dynamic-wind:
(with-result
(call/cc
(lambda (escape)
(with-exception-handler
(lambda (E)
(escape E))
(lambda ()
(dynamic-wind
(lambda ()
(add-result 'in-guard))
(lambda ()
(add-result 'thunk))
(lambda ()
(add-result 'out-guard)
(raise 1))))))))
⇒ (1 (in-guard thunk out-guard))
This is what happens when we raise an exception from the thunk of a
dynamic-wind and the from the out–guard of the same:
(with-result
(define count 0)
(call/cc
(lambda (escape)
(with-exception-handler
(lambda (E)
(add-result (list 'handler E))
(escape E))
(lambda ()
(dynamic-wind
(lambda ()
(add-result 'in-guard))
(lambda ()
(add-result 'thunk)
(raise 1))
(lambda ()
(add-result 'out-guard)
(raise 2))))))))
⇒ (2 (in-guard
thunk (handler 1)
out-guard (handler 2)))
the first exception is forgotten when escape attempts to exit the
dynamic extent of the thunk.