[E-Lang] E Project, Documentation, and new programmers
Dan Bornstein
danfuzz@milk.com
Thu, 12 Apr 2001 11:01:04 -0700 (PDT)
Tyler Close writes:
>I think the best solution here is actually to deviate from the expression
>style syntax and have an explicit "return" keyword. Then it would be
>perfectly safe to have the default guard be ":any". I am not sure, but I
>think following this path would also make it possible to have E loops
>terminate with a return rather than throwing an exception.
Note that "return" is really just as much of a deviation from expression
style as "throw," and if you squint your eyes just right you can implement
the former in terms of the latter (not that it'd be particularly efficient
to do this directly, but it's a passable story). Using pseudo-Java (because
I know I'll get E hopelessly wrong), you could expand "return" to a kernel
form something like this:
Object foo (Object x)
{
if (blort (x))
return x;
}
=>
Object foo (Object x)
{
Throwable returner = new Throwable ();
Object returnValue = null;
try
{
if (blort (x))
{
// original return statement expands as follows
returnValue = x;
throw (returner);
}
}
catch (Throwable t)
{
if (t != returner)
{
throw t;
}
return returnValue; // raw return
}
return null;
}
If you bundle the return value into the Throwable (e.g., make a
ReturnThrowable that has a performReturn() method which sets some internal
state and does the throw, and the catch extracts the return value), then
you're about 80% of the way towards having full downward-passing
continuations, something I'd be very much in favor of.
-dan