Allen's lambda syntax proposal

Maciej Stachowiak mjs at
Fri Dec 5 10:22:00 PST 2008

On Dec 5, 2008, at 10:00 AM, Jon Zeppieri wrote:

> On Fri, Dec 5, 2008 at 12:39 PM, Maciej Stachowiak <mjs at>  
> 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.

So return from a lambda is sometimes but not always a runtime error?  
Other times it can return through multiple levels of function calls  
without raising an exception? That seems pretty bad for ease of  
understanding and for performance of implementations. If you do this:

[1 2 3].map(lambda (x) { return x + 1; })

I think it would be better for that to be a syntax error than to make  
the containing function return 2.

It seems to me the current design prioritizes lambda as a desugaring  
construct or building block for imperative-style control flow, over  
use as an actual first-class function. I assume break and continue  
inside a lambda have similar issues.


More information about the Es-discuss mailing list