Alternative syntax for closures
Rémi Forax
forax at univ-mlv.fr
Mon Jul 7 06:19:45 PDT 2008
Neal Gafter a écrit :
> One idea we tossed around a few months ago, without any real
> conclusion, was to replace the curly braces with parens. Things have
> changed a bit since then; I'd now use a dash-greater instead of
> equals-greater. I think we could consider using the parens for
> restricted closures (for those of you who haven't been paying
> attention, restricted closures can't use return, break, or continue to
> a target outside the closure) and curly braces for the unrestricted form.
>
> /RestrictedLambdaExpression/
> ( /FormalParameterDecls////_/opt/ /// *—**>* ////BlockStatements_/opt
> / ////////Expression///////_/opt/ /////// ////)
> /RestrictedFunctionType/
> ( /TypeList////_/opt/ /// *—**>* /Type/ /ThrowsClause////_/opt/ /// )
>
> /UnrestrictedLambdaExpression/
> { /FormalParameterDecls////_/opt/ /// *—**>* ////BlockStatements_/opt
> / ////////Expression///////_/opt/ /////// ////}
> /UnrestrictedFunctionType/
> { /TypeList////_/opt/ /// *—**>* /Type/ /ThrowsClause////_/opt/ /// }
>
> For example (this is /not/ intended to be a motivational example):
>
> *(int, int **—**> int) plus = (int x, int y **—**> x+y);*
> *{ Answer —**> void } block = { **Answer answer —**>
> System.out.println(answer); };*
>
> The parens instead of curly braces emphasize to the reader that it is
> an expression closure, which is one of the principal use cases for the
> restricted form.
>
> Without an active working group, I don't expect to make any major
> syntax changes in the prototype, but I wanted to get this out there
> for you to think about.
>
> Regards,
> Neal
I've just written a blog about an alternative syntax:
http://weblogs.java.net/blog/forax/archive/2008/07/alternative_syn.html
Remi
More information about the closures-dev
mailing list