[E-Lang] when-catch-finally (was: pending revision of E in a Walnut)

Mark S. Miller markm@caplet.com
Wed, 22 Aug 2001 15:09:45 -0700


Since Alan's "finally" suggestion seems to only have virtues and no flaws, 
and (because of the analogy with try-catch) it makes the language seem no 
more complicated (and perhaps even a bit simpler), I'm happy to incorporate 
Alan's suggestion into the language spec.  And eventually even into the 
implementation ;).  So

At 08:22 AM Wednesday 8/22/01, Marc Stiegler wrote:
>            when (nextCar <- moveTo(toX,toY)) -> done(moving) {
>                println(name + " arrived, next car about to start moving")
>                moveRemainingCars()
>            } catch e {
>                println("car died: " + e)
>                moveRemainingCars()
>            }

could be written:

            when (nextCar <- moveTo(toX,toY)) -> done(moving) {
                println(name + " arrived, next car about to start moving")
            } catch e {
                println("car died: " + e)
            } finally {
                moveRemainingCars()
            }

Let's use these example to evaluate the proposed semantics change.  In both 
cases, if the done-clause throws an exception, would you expect the 
catch-clause to catch that as well, with "e" bound to the exception?  (The 
current behavior is that the catch-clause only gets run if "moving" turned 
out to be a broken reference.)  In imagining what you'd expect, imagine that 
you only skimmed the manual, or read it carefully only a long time ago. Call 
this "what you expect when you're in a hurry".

Likewise, with Alan's proposal we now have the corresponding question: Would 
you expect the finally-clause to run even if the done-clause throws?  Even 
if the catch-clause throws?  Even if the resolution of "(nextCar <- 
moveTo(toX,toY))" fails to match the pattern "moving"?  Even if the problem 
extracted from the broken reference fails to match the pattern "e"?

In my proposed control-flow-oriented expansion, the answer to all of these 
questions is yes.  If this corresponds to our expectations-in-a-hurry, then 
we're cool.


        Cheers,
        --MarkM