Allen's lambda syntax proposal

David-Sarah Hopwood david.hopwood at
Fri Dec 5 20:50:51 PST 2008

Peter Michaux wrote:
> The syntax ^(){} has a semicolon insertion ambiguity. What does the
> following mean?
>   x = x
>   ^(){}

It's not ambiguous; it would mean "x = x^(){}", which is (in this case)
a syntax error.

'-' and '/' already have a similar issue of possibly unexpected
parsing when they occur at the beginning of a line. It's just that
it is rare to intend to start an ExpressionStatement with a unary
minus or a regexp literal, so this doesn't occur very often in
practice. It's not clear how often programmers will intend to start
an ExpressionStatement with a lambda, although I can see that this
might be more common.

Note that programmers who never deliberately rely on semicolon insertion
will not be surprised by this example; they will consider writing
"x = x" without an terminating semicolon to have been their mistake.

David-Sarah Hopwood

More information about the Es-discuss mailing list