Different semantics should have different-looking syntax

Brendan Eich brendan at mozilla.com
Sat May 21 13:24:57 PDT 2011


On May 21, 2011, at 1:18 PM, Dmitry A. Soshnikov wrote:

> First, this proposal is also useful for JS. Especially the semantics of returning from a closure (so this is what TCP addresses, now I see that it's not the "Transmission Control Protocol" :D, and actually I myself addressed this issue long time before - http://bit.ly/eVq5ob (JFTR), though without mentioning Tennet's principle).

(Tennent)


> Currently we have to use try-catch to handle simple search engine with using e.g. `forEach` for that. So using `return` inside the block-closure will exit all block contexts -- as an exception would be thrown and caught at non-block level (i.e. at function level), right?

In the spec, new completion types that act like exceptions, yes. I'm not proposing that we reify BREAK, CONTINUE, and RETURN as catchable exceptions, though.


> At least Ruby uses such a way. And we use "return-less" return, i.e. just via control-flow structure, then a block return to the caller.

I argue this wants http://wiki.ecmascript.org/doku.php?id=strawman:completion_reform in the strawman.


> It seems a good addition.

Thanks, I think so too.


> It turns out now that it's really a dilemma what to choose -- arrows or blocks... have to think.

Arrow function syntax is "just syntax". I will drop it if we can agree on block lambda revival. As @_sjs (Sami Samhuri) tweeted at me, "We'll always have function." ;-)

/be

> 
> Dmitry.
> 
>> Alternatives (ignoring keyword issues) that look more like function syntax (Peter's suggestion of lambda (x) { x * x }, e.g.) seem worse in this light: block lambdas do follow the correspondence principle, which is novel to JS with its C statements for control effects heritage.
>> 
>> In this light, the use of | | to bracket formal parameters seems better than anything using (...) {...}. This is not an overriding concern, but it seems worth mentioning. We want block-lambdas or any such TCP-pure new thing to have syntax that says "look! something new here".
>> 
>> And, since the strawman builds on block syntax, we want the new form to have syntax that "looks like a block", in which you'd expect TCP purity for break, continue, return, |this|, and arguments.
>> 
>> Thus, block lambdas that start with { and have lightweight parameter delimiters.
>> 
>> /be
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
> 
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



More information about the es-discuss mailing list