On Sat, Nov 7, 2020 at 5:51 PM Chris Vine <[email protected]> wrote:


> For my elucidation, why?  The indentation of the code isn't ideal but
> the whole purpose of dynamic-wind is to handle code leaving the thunk in
> case of exception, application of a continuation object or regular
> return.
>

You're right about the second and third cases, but not the first.  Raising
an exception *simply* calls the current exception handler, which is then
free to return to the point of call like any other procedure.  In such a
case, the after-thunk is not run, since dynamically you are still inside
the main thunk.  This is a fundamental distinction between Lisp exceptions
and every other language's exceptions.

Only if the exception handler uses call/cc to escape back to the dynamic
context where the handler was set up is the after-thunk run.  This is done
for you automatically if you use `handle-exceptions` or `chicken-case` or
R7RS `guard`.

If you raise an exception with `abort` or `error`, then if the handler
returns, another exception "unexpected return from handler" is raised.

Note also that when the thread scheduler switches to a new thread, any
before- or after-thunks are not run, as the thread is supposed to be
unaware that the switch happened.



John Cowan          http://vrici.lojban.org/~cowan        [email protected]
Would your name perchance be surname Puppet, given name Sock?
                --Rick Moen

Reply via email to