A syntax option (function types versus arrays)

Peter Levart peter.levart at marand.si
Tue Mar 2 03:41:02 PST 2010


On Tuesday 02 March 2010 08:58:28 Joshua Bloch wrote:
> Peter,
> 
> On Mon, Mar 1, 2010 at 11:49 PM, Peter Levart <peter.levart at marand.si>wrote:
> 
> > I think we don't need statement lambdas if we allow expression to be
> > preceeded by statements (like in block expression of CfJ0.6b):
> >
> > Lambda:
> >  '(' FormalParameters_opt '->' Statements_opt Expression ')'
> >
> > for void lambdas "void" keyword could be defined as expression of type
> > void:
> >
> > (->void) lambda = (-> System.out.println("Hello!"); void);
> >
> 
> Why do you like this better than the current proposal?
> 
>     Josh
> 

Regarding function types syntax I don't really have a preference to the order of (parameter types, return type, throws types) but I think that a syntax that composes well (nests) is better. In this regard the current proposal is not the best of all alternatives. I also think that visual similarity between the syntax-es of function types and lambda expressions is desired although not necessary.

Recently I had a suggestion that is actually similar to the Neal's preferred syntax but with the order of return type reversed:

FunctionType:
  ReturnType '#' '(' ParameterTypeList_opt Throws_opt ')'

This can be viewed as:

FunctionType:
  ReturnType '<-' '(' ParameterTypeList_opt Throws_opt ')'

It nests better and at least Arabs would find it natural ;-)


Regarding preference to expression lambdas, I think they provide a way to avoid defining the meaning of "return" at present time. The 1st release of lambdas in JDK7 could simply disallow "return". Experience gathered from the milions of Java developers in comming years would help shape a decision of what to do with "return" (be it local or transparent) for the next release in JDK8 which could add statement lambdas as well.

I think that gradual additions to the language where 1st addition leaves open options for the future is a safe path. We may argue till the end what is going to work better but why not just wait and see what is going to be missed the most?

Regards, Peter


More information about the lambda-dev mailing list