This wins on so many levels:
 * Short but C-like myList.map((x) x*x) syntax for the most common cases, where 
TCP doesn't matter.
 * Full TCP support via an entirely new, but still pretty C-like, syntax with 
myList.map((x) do { … }).
 * The two are sufficiently close to each other and to the existing syntax to 
be recognizable as functions, but sufficiently different to convey new 
semantics.

The earlier Prototype 1.6 example:

inGroupsOf(number, fillWith) {
 fillWith = Object.isUndefined(fillWith) ? null : fillWith;
 return this.eachSlice(number, (slice) do {
   while(slice.length < number) slice.push(fillWith);
   slice;
 });
},

inject(memo, iterator, context) {
 iterator = iterator.bind(context);
 this.each((value, index) do {
   memo = iterator(memo, value, index);
 });
 return memo;
},

invoke(method) {
 var args = $A(arguments).slice(1);
 return this.map((value) value[method](...args));
},

From: [email protected] [mailto:[email protected]] On 
Behalf Of David Herman
Sent: Tuesday, March 06, 2012 17:58
To: Brendan Eich
Cc: es-discuss
Subject: Re: optional "function" keyword

On Mar 6, 2012, at 2:56 PM, Brendan Eich wrote:


David Herman wrote:


Moreover, if you wanted to do some control along with an expression, you could 
use do-expressions:

    myList.map((x) do { for (...) { ... } f(x) })

Note that combination (expression closures + do-expressions) brings back the 
exact same expressiveness of block-lambda.

Not so, because no TCP. Only block-lambdas preserve TCP fully.

Says you! :)

To be clear: what I'm suggesting is that expression closures would *not* be 
syntactic sugar for statement bodies, but rather would be TCP-respecting. Most 
of the time this wouldn't even be noticeable, until you use do-expressions.

Dave

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to