Syntax decision

Pavel Minaev int19h at gmail.com
Fri Sep 30 15:18:45 PDT 2011


Note that most such special cases also have 1) a single lambda that 2)
occurs in the final argument position. So I think that this is an argument
for some kind of syntactic sugar akin to what Ruby has - where you can
write:

  foo.bar(1, 2, 3) {|x,y,z| ...}

instead of:

  foo.bar(1, 2, 3, {|x,y,z| ...})

i.e. moving the lambda outside the parentheses, and making it look more like
a statement with a body than a function call.

I don't think this is something worth pursuing for the first version,
though. ()->{} is good enough in practice, and extra syntactic sugar can
always be slapped on top when and if needed.

On Thu, Sep 29, 2011 at 10:11 PM, Zhong Yu <zhong.j.yu at gmail.com> wrote:

> Since 0-arg case is quite common, as in Runnable and Callable, we'll
> have many use cases like
>
>    cache.get(key, ()->load(key));
>
>    tasks.add(()->{ doSomething(arg);});
>
>    transaction(()->{
>        statement1;
>        statement2;
>    });
>
> Not bad after staring at them for 30 minutes. But too many consecutive
> punctuation marks are there... quite dizzy at first sight.
>
> How about a single punctuation mark, currently unused, as syntax sugar
> for "()->". Too cheesy?
>
> - Zhong Yu
>
>


More information about the lambda-dev mailing list