Allen's lambda syntax proposal

David-Sarah Hopwood david.hopwood at industrial-designers.co.uk
Thu Dec 4 12:02:24 PST 2008


Yuh-Ruey Chen wrote:
> Brendan Eich wrote:
>> C# uses (a, b, c) => ... but in JS the comma operator makes that nasty
>> to parse top-down. I think the only candidates have to be of the form
>>
>> ^(a, b, c) {...}
>>
>> (^ could be another character, but it seems to beat \ as others have
>> noted), or else the Smalltalky
>>
>> { |a, b, c| ... }
>>
>> At this point we need a bake-off, or a convincing argument against the
>> unusual vertical bar usage.
> 
> Here's a possible technical issue that might not apply to ES: Ruby
> blocks params can't have default arguments according to
> http://eigenclass.org/hiki.rb?Changes+in+Ruby+1.9#l9 :
> 
>     The new syntax allows to specify default values for block arguments,
>     since
> 
>      {|a,b=1| ... }
> 
>     is said to be impossible with Ruby's current LALR(1) parser, built
>     with bison.

There's an ambiguity here that is independent of what kind of parser
is used (I don't know whether it is the same issue as in Ruby).
Consider:

  {|a=1|2, b|c}

Is the argument list (a = 1|2, b) with body {c}, or is it
(a = 1) with body {2, b|c}?

This ambiguity could be resolved by restricting expressions used as
default argument initialisers, but it is not clear why they should
be restricted, given that other possible concrete syntaxes for
lambda do not have this problem.

IMHO this does count as a "convincing argument against the unusual
vertical bar usage", if we want default arguments (and I think we do).

However, I'd like to suggest that it may be premature to be deciding
on the concrete syntax of lambda, without knowing its abstract syntax.
(The issue that MarkM raised about unintentionally leaking a value
that happens to be evaluated in tail position, for example, needs to
be dealt with at the abstract syntax level.) The same point applies
to the syntax of object literals.

That will require some notation for discussing abstract syntax, on
which I'll start another thread.

-- 
David-Sarah Hopwood


More information about the Es-discuss mailing list