Reuse 'do' keyword instead of hash sign (#)
David Goodenough
david.goodenough at linkchoose.co.uk
Mon Jun 20 08:52:49 PDT 2011
Maybe if you want a keyword, use "lambda".
So your i.e's below:-
lambda()(5)
lambda(){return 5;}
lambda(int x,int y) { if (x>y) return x; else return y; }
button.onClick(lambda(Event e) { println("button clicked"); });
This is not to say that we should use a keyword, rather a suggestion
if a keyword is to be used what it might be.
This is offered in the "calling a spade a spade" tradition.
David
On Saturday 18 Jun 2011, 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