Allen's lambda syntax proposal

Lex Spoon spoon at google.com
Wed Dec 17 13:42:56 PST 2008


On Mon, Dec 1, 2008 at 3:19 PM, Allen Wirfs-Brock
<Allen.Wirfs-Brock at microsoft.com> wrote:
> Just to clarify some speculation, the syntax I proposed ({||}) was
> solely inspired by Smalltalk and tempered by the parsing realities
> of a C-like syntax.  Any similarities to Ruby constructs are probably
> examples of parallel evolution under similar environmental pressures.
> I suspect that designers of other languages with C-like syntax
> (C# comes to mind with its () => expr "lambda" syntax) did not
> have the experience or goal of using closures to create control
> abstractions (which often requires passing multi-statement closures)
>  and so arrived at a more function-like concise closure syntax.

I can share some history for the => form.  It's disconcerting that
everyone associates it with C#, because they are open about copying
the syntax from Scala.  Scala's designer, Martin Odersky, most
definitely had in mind that people could use functions for control
flow, and in fact he treats it as the primary way to do control flow
in Scala.  I believe Martin got this syntax most directly from ML's
"fn" expressions.  He noticed that you don't really need the keyword.

The development for ML->Scala->C# actually looks a lot like is
happening in ES discussions.  Once a function literal syntax is
available, people really want to use it, and the syntax is pressured
to get shorter and even to get its keyword dropped in favor of
symbols.

On this list, the => form has so far been dismissed due to parsing
concerns.  If that's the only reason, let me try and allay that worry
and put that horse back in the race.  Scala also has a comma operator,
but it still manages to parse the => syntax.  They way it does it is
to initially parse an expression and then, if it sees a =>,
reinterpret what it has seen so far as a parameter list.  It's an
unusual parsing strategy, but it works well and the issue is
localized.

IMHO, x => x+1 really looks like a function literal, so that's the
color I'd paint the bike shed.  I agree with Allen and others, though,
that any version that drops the keyword will make the form more useful
in practice.

-Lex


More information about the Es-discuss mailing list