Reuse 'do' keyword instead of hash sign (#)
Rémi Forax
forax at univ-mlv.fr
Sat Jun 18 11:19:45 PDT 2011
In my opinion, the main problem of do is that if you have a lambda
in a lambda it's not that readable because do(int i) is
a syntax which is too similar to a method call.
I really prefer the BGGA syntax (with a single arrow instead
of a double one) because it helps to see the whole lambda
(enclosed in curly braces).
But if you look for something different from #,
why not ,\ (comma + backslash) ?
Rémi
On 06/18/2011 01:11 PM, 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