return when desugaring to closures

Yuh-Ruey Chen maian330 at gmail.com
Sat Oct 11 11:23:39 PDT 2008


David Herman wrote:
> > Does the |var| within the lambda define a var in the function body,
> > and does that var declaration hoist to the top of the function body?
>
> Good catch, thank you. Since `lambda' is designed to have no implicit semantics, it can't introduce a new `var' frame. IOW, the `var' would still be hoisted to the nearest enclosing `function', not `lambda'. I'll add this to the wiki page.
>
> Thanks,
> Dave
>   

Also, I wonder why lambda in it's block-less form is restricted to
expressions. I mean, why can't the following be valid?

lambda() for (p in x) ...
lambda() if (cond) ... else ...

The reason block-less functions are restricted to expressions is that
they have an implicit return. With lambdas, there is no implicit return
- the lamba's returned value is always going to be the value of the tail
position expression.

With this change, this would simply the grammar down to:

Expression ::= ... | lambda Formals Statement

The advantage of this is that it will allow in the future more seamless
"statement" macros that follow C conventions, i.e. a statement can
include a nested block-less statement, e.g. stmtMacro() stmt.


More information about the Es-discuss mailing list