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

Jack Moxley jack at moxley.co.uk
Mon Jun 20 01:12:19 PDT 2011


I think you misunderstood me, I suppose it really depends on whether you conceptually consider lambda expressions to be objects and thus typed, or you don't. Which I, for right or wrong do.
      _____  

  From: Alessio Stalla [mailto:alessiostalla at gmail.com]
To: Jack Moxley [mailto:jack at moxley.co.uk]
Cc: Stephen Colebourne [mailto:scolebourne at joda.org], lambda-dev [mailto:lambda-dev at openjdk.java.net]
Sent: Mon, 20 Jun 2011 09:08:19 +0100
Subject: Re: Reuse 'do' keyword instead of hash sign (#)

On Mon, Jun 20, 2011 at 9:46 AM, Jack Moxley <jack at moxley.co.uk> wrote:
> I'm not sure that's a fair argument, there are many define type keywords: class, int, float, etc...

But those are all statements, not expressions; i.e. these are all illegal:

Class<?> myClass = class MyClass {}
int foo = int bar = 3;
callSomeMethod(float x);

> Although do is used for control and not for type definition so it would be wrong in that sense.

The analogy with "type definition" keywords does not hold. A closure
is not a type, it's an object, and lambda expressions are, well,
expressions that return such an object.

> On 20 Jun 2011, at 08:11, Stephen Colebourne <scolebourne at joda.org> wrote:
>
>> No from me too.
>> (Keywords introduce statements in Java, not expressions.)
>> Stephen
>>
>> 2011/6/18 Marcin Wiśnicki <mwisnicki at gmail.com>:
>>> 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