return when desugaring to closures

David-Sarah Hopwood david.hopwood at industrial-designers.co.uk
Sat Oct 11 11:59:42 PDT 2008


Peter Michaux wrote:
> On Sat, Oct 11, 2008 at 7:12 AM, David-Sarah Hopwood
> <david.hopwood at industrial-designers.co.uk> wrote:
>> Yuh-Ruey Chen wrote:
> 
>>> I read through the strawman:lambdas proposal and saw that it did not
>>> mention anything about |var|, e.g.
>>>
>>> (function() {
>>>     lambda {
>>>        var x = 10;
>>>     }();
>>>     return x;
>>> })()
>>>
>>> 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?
>> To satisfy Tennent's correspondence, all var statements must hoist in the
>> same way ignoring lambdas -- i.e. to the top of the innermost enclosing
>> function body (if not in the global scope).
> 
> How to define a variable that is local to the enclosing lambda?

Use 'let'. The body of a lambda is a block, so a variable declared with
'let' will be local to that block (this still satisfies Tennent's
correspondence, in both the expression and statement forms as described in
<http://gafter.blogspot.com/2006/08/tennents-correspondence-principle-and.html>.)

> Isn't the ability to do that essential?

Yes.

-- 
David-Sarah Hopwood



More information about the Es-discuss mailing list