[e-lang] Variations on When-Catch
Kevin Reid
kpreid at attglobal.net
Tue Dec 21 06:38:33 EST 2004
On Dec 20, 2004, at 22:01, Mark Miller wrote:
> when (milesTraveled() // ksPerMile) -> done(ksTraveled) {
> # do something with ksTraveled
> } catch problem {
> # handle problem
> } finally {
> # do regardless
> }
>
> Let's say that ksPerMile is zero. The immediate expr will immediately
> do a divide by zero and immediately throw an exception. The expression
> defining the done function is never evaluated, so the done function is
> never instantiated, and the underlying Ref.whenResolved will never get
> called. The catch and finally clauses are part of this done function,
> and never get invoked. The extent of execution they cover only begins
> after the '->'.
I now understand why it would be difficult to catch failures from all
->()-> elements. To rephrase, the first ()-> is part of the existing
immediate control flow (which can catch), and the done function is
handled by the catch clause of 'when'; however, an intermediate ->()->
is in neither of these immediate-control-flow dynamic scopes.
> Now that I see this, I see that it is confusing. Given that we must
> explain this confusing point, I think it's no more confusing that, for
> chained '->'s, the extent covered by these clauses only begins after
> the last '->'.
>
> I don't think we should "fix" this. Rather, we should deprecate the
> use of 'finally' in a when-catch with the intention of removing it
> from the language. We should carefully document the remaining issue of
> what the catch clause does and doesn't cover.
I think finally-in-when should not be deprecated. The finally clause
covers the same code that the catch clause does, and neither covers the
immediate expression since it *is* immediate. While this is potentially
confusing, it's far too useful to lose, in the cases where one needs
it.
(There are six occurrences of when...finally in Den.)
One might think of it like this:
when (milesTraveled() // ksPerMile) -> done(ksTraveled) {
# do something with
ksTraveled
} catch problem {
# handle problem
} finally {
# do regardless
}
--
Kevin Reid <http://homepage.mac.com/kpreid/>
More information about the e-lang
mailing list