Syntax decision
Paul Benedict
pbenedict at apache.org
Wed Sep 28 08:58:02 PDT 2011
On Wed, Sep 28, 2011 at 10:46 AM, Brian Goetz <brian.goetz at oracle.com>wrote:
> Yes, there are lots of possible hacks like this, including:
> - forcing unary inferred-type lambdas to not use parens:
> x -> e instead of allowing (x) -> e
> - Not allow casting of nilary lambdas without specifying ()
> (T)() -> e instead of allowing (T) -> e
>
> But all of these introduce irregularities into the syntax, for the sake
> of supporting an extra case because people find
>
> () -> e
>
> to be ugly. This increases the complexity of the syntax and means there
> are more special cases to learn.
>
> With the current approach, there is only one special case:
> - All lambdas consist of paren-args-paren-arrow-body
> - For the special case of unary, type-inferred lambdas, you can omit
> the parens: x -> x+1
>
> Turning that into "you *must* omit the parens" means that all users,
> even those who don't care about the nilary form, must learn another rule.
>
> Better suggestions?
>
>
If a lambda needs no arguments and if () looks ugly (nods), is this anymore
palatable?
(void) -> e
More information about the lambda-dev
mailing list