Reuse 'do' keyword instead of hash sign (#)

Brian Goetz brian.goetz at oracle.com
Sun Jun 19 17:07:02 PDT 2011


In a word: no.

On 6/18/2011 7:11 AM, Marcin Wiśnicki wrote:
> This is a repost from 2010/8 since apparently now syntax is up for
> discussion but wasn't back then.
> Also I didn't like any proposal from "Syntax poll" thread ;(
>
> You can call it "do" syntax ;)
> I didn't have the time to think it thoroughly or follow recent java7/8
> developments but here it goes:
>
> Would it be possible to change the clumsy '#' operator to 'do' keyword ?
> I.e.:
>
>   do()(5)
>   do(){return 5;}
>   do(int x, int y) { if (x>y) return x; else return y; }
>   button.onClick(do(Event e) { println("button clicked"); });
>
> "strawman" syntax example:
>
>    list.filter( #(Foo t)(t.length()>  3) )
>        .map( #(Foo t)(t.barCount) )
>        .max();
>
> becomes:
>
>    list.filter( do(Foo t)(t.length()>  3) )
>        .map( do(Foo t)(t.barCount) )
>        .max();
>
> I find it more readable; using special characters feels a bit
> like perl (noisy), especially when combining multiple lambdas.
> It even makes sense if you parse it as english.
>
> Don't know what to do with anonymous function type but it could remain as '#'.
>
> Pros:
>   - more readable
>   - makes sense
>   - like '#' needs only 1-lookahead to disambiguate from do-while '(' vs '{' [1]
>   - did I mention it's more readable ?
>
> Cons:
>   - none (that I could think of)
>
> [1] Automatic Resource Management from Coins wanted to use 'do' but I
> see they have switched to 'try' so no problem there.
>
> PS. Please CC me when responding, thanks.
>


More information about the lambda-dev mailing list