Block lambda is cool, its syntax isn't

François REMY fremycompany_pub at yahoo.fr
Thu Jan 12 14:23:55 PST 2012


Am I wrong if I say there not a bigger issue with block lambda than with the 
current object notation on the matter?

I mean, does that code mean anything useful?

    function() {
        {|a,b| a+b};
    }

If not (as it seems to me), it means that a block lambda will not be used as 
a statement by itself. If it's the case, it should defined as an Expression 
only, where there's no anonymous block to conflict the syntax. That solution 
has been chosen for object notation in the past. That way,

    function() {
        {
            (a, b)
            a.add(b)
        }
    }

would still be an anonymous block where

    function() {
        asyncAction(..., { (a, b) a.add(b); } }
    }

would be a block lambda as an argument of an async function. No semantic 
change for an identical syntax, in regards to strict ES5.

The case where you would like to use a block lambda as a stament can be 
resolved by adding parenthesis, like with the current object notation. And 
since I still continue to hope we'll ditch the unprefixed anonymous block in 
some future revision of ES, that very small edge case could vanish at the 
same time.

Does it seems possible/acceptable?




-----Message d'origine----- 
From: Allen Wirfs-Brock
Sent: Thursday, January 12, 2012 10:38 PM
To: Thaddee Tyl
Cc: es-discuss at mozilla.org
Subject: Re: Block lambda is cool, its syntax isn't


On Jan 12, 2012, at 1:26 PM, Thaddee Tyl wrote:

> I have heard many fellow programmers say that, while block lambdas
> would be welcome, Ruby's |a, b| syntax is ugly.
> I thought I was the only one feeling this way, but since I am not, I
> would like to ask why the parentheses cannot be used there.
>
>    { (a, b) a + b }
>
> cannot conflict with any existing program; at least I don't see how it 
> can.

but it is ambiguous with  other currently valid statement blocks such as:

   { (a, b) + b}

or

  { (a,b)
     a+b
  }

Allen
_______________________________________________
es-discuss mailing list
es-discuss at mozilla.org
https://mail.mozilla.org/listinfo/es-discuss 



More information about the es-discuss mailing list