return when desugaring to closures

Mark S. Miller erights at google.com
Thu Oct 16 19:07:02 PDT 2008


On Thu, Oct 16, 2008 at 5:49 PM, David-Sarah Hopwood
<david.hopwood at industrial-designers.co.uk> wrote:
> [lots of good stuff snipped]

I agree.

> The degenerate syntax "let {...}" allowed by this grammar at first-sight
> doesn't seem very useful, until you realize that it has a similar effect
> (apart from not preventing hoisting of 'var' declarations past the
> 'let') to the Crockford module pattern "(function() {...})()".

Since non-var declarations will now be lexically block scoped, all
these non-var good features but one of Crock's module pattern will
also be present for simple blocks. Since lambda preserves TC, it must
be thus.

The one additional feature provided both by Crock's module pattern and
by degenerate let is turn EcmaScript effectively into an expression
language. Rather than saying

    ...(3 + function(){while(...){...}; return 4;}())...

we'd now be able to say

    ...(3 + lambda{while(...){...}; 4}())...
or even
    ...(3 + let{while(...){...}; 4})...

Of course, if you want a begin/end that works for vars as well, you'd
still have to use Crock's module pattern.

-- 
    Cheers,
    --MarkM


More information about the Es-discuss mailing list