[E-Lang] pending revision of E in a Walnut

Marc Stiegler marcs@skyhunter.com
Wed, 22 Aug 2001 08:22:01 -0700


> At 11:10 AM Tuesday 8/21/01, Marc Stiegler wrote:
> >I am not all the way through Alan's comments, but one proposal for an
upward
> >compatible enhancement to the language caught my attention. Could/should
the
> >when-catch construct include a "finally" clause like the try-catch? Alan
> >noted that one of my examples would be simpler if we had such a beast. If
it
> >is falling-off-a-log easy, I think it is a good idea.
>
> It would certainly be trivial to implement.  It also seems like a good
idea
> to me.  Could you post the example and Alan's comments?

Alan's comment was just that it looked like "finally" would be good here. In
this example of recursive usage of when-catch, "moveRemainingCars()" needs
to be done finally: no matter the outcome of moving one car, you still want
to move the next one.

def moveAllCarsInSequence(cars,toX,toY) {
    def carI := 0
    def moveRemainingCars() {
        if (carI < cars size()) {
            def nextCar := cars[carI]
            carI += 1
            def name := nextCar <- getName()
            when (nextCar <- moveTo(toX,toY)) -> done(moving) {
                println(name + " arrived, next car about to start moving")
                moveRemainingCars()
            } catch e {
                println("car died: " + e)
                moveRemainingCars()
            }
        }
    }
    moveRemainingCars()
}
moveAllCarsInSequence([car1,car2,car3],3,4)