Allen's lambda syntax proposal

Jon Zeppieri jaz at bu.edu
Fri Dec 5 10:00:02 PST 2008


On Fri, Dec 5, 2008 at 12:39 PM, Maciej Stachowiak <mjs at apple.com> wrote:
>
> What exactly does return from a lambda mean? Let's say I do this:
>
> function F(x) { return lambda(n) { return x + n; } }
> function G(h) { return h(1) +1; }
> var H = F(1);
> G(H);
>
> What is the value of the last expression and why?

Based on the lambda and return-to-label strawmen, It's an error.  Dave
presents a desugaring of function to lambda, where each function body
is given a label at the bottom:

lambda(x0,...,xn,...$rest) {
    let $THIS = thisRegister;
    let arguments = makeAlias([[lambda() x1, lambda($x1) x1 = $x1],
                               ...,
                               [lambda() xn, lambda($xn) xn = $xn]],
                              $rest);
    $RETURN: { Body; void 0 }
}


'return e' without a label desugars to:

   return : $RETURN e

But, from the return-to-label strawman:

"The dynamic return point associated with the label must still be live
when the return statement is invoked; otherwise it is a dynamic error,
i.e., an exception is raised."

A label is an escape continuation.  Once control has returned past the
point where the continuation was captured, it's dead, and it can't be
resumed.

-Jon


More information about the Es-discuss mailing list