Block lambda is cool, its syntax isn't

Oliver Hunt oliver at apple.com
Wed Jan 18 11:37:56 PST 2012


On Jan 18, 2012, at 10:36 AM, Gavin Barraclough wrote:

> On Jan 18, 2012, at 2:09 AM, Brendan Eich wrote:
>>   x = y
>>   ^{z: w}
> 
> On Jan 18, 2012, at 9:05 AM, Oliver Hunt wrote:
>> Alas ^ is syntactically ambiguous in the non-argument case:
>> foo
>> ^{...}
> 
> The ambiguity here doesn't seem particularly troubling. Under ASI this parses in a sensible fashion.

It doesn't

a
^
b

does not get any ASI, and is parsed (correctly) as a^b


> This seems unlikely to cause any confusion in real usage, since it only effects an object literal as an operand to a bitwise operator.

I dislike the | mode quite a lot, the only obvious reason for that proposal existing is some peoples current love of ruby :)  Why not use the C++ lambda syntax?  or the MSVC lambda syntax? or the haskell syntax? etc, etc (Obj-C uses the ^ that we've already demonstrated is ambiguous :D )

> 
> On the other hand, reuse of | seems somewhat more awkward. Based on the block lambda revival proposal, I believe:
> 	{|x = (a&b)| x}
> 	{|x = (a&&b)| x}
> 	{|x = a&b| x}
> Are all valid block lambdas, but:
> 	{|x = a&&b| x}
> Isn't.
> Allowing an arbitrary subset of infix operators in initializer expressions seems an unfortunate wart, and potentially confusing to users of the language.
> 
> On Jan 18, 2012, at 2:09 AM, Brendan Eich wrote:
>> 2. The TCP conformance makes anything like function (params) {body} an anti-pattern. Changing function to ^ does not avoid this problem. We want block-lambdas to look different from functions.
>> 
>> (2) is an overriding objection in my view.
> 
> That's a fair point.
> For my tastes reusing | as delimiters to the parameter lists is a step too far away from function-like syntax, particularly if it restricts an arbitrary subset of infix operators from initializers.
> 
> I'd suggest changing the terminator for the parameter list to something other than | ...
> 	{|:  foo() }
> 	{|x,y:  foo(x,y) }
> But I'd hate myself if I did. ;-)
> 
> G.
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120118/b1941345/attachment-0001.html>


More information about the es-discuss mailing list