Function types syntax
Zdenek Tronicek
tronicek at fit.cvut.cz
Tue Jan 26 02:15:48 PST 2010
Peter Levart napsal(a):
> 2nd order example from above repeated here for comparison:
>
> ##int(String)(throws IOException)(String)(throws SQLException)
>
> with proposed syntax:
>
> #(String: #(String: int throws IOException) throws SQLException)
>
I think that more important than different syntax are parens in your syntax:
#(#int(String)(throws IOException)) (String)(throws SQLException)
vs.
#String: #String: int throws IOException throws SQLException
> The following is not something I'm proposing. It's just an idea I'm
> dreaming about:
>
> The above function types syntax could be nicely paired with the following
> syntax for lambda expressions that John Rose already proposed in a similar
> form:
>
> LambdaExpression:
> '#' '(' FormalParametersList_opt ResultParameter_opt ')' Block
>
> ResultParameter:
> ':' FormalParameter
>
>
> Examples:
>
> #(:void) printHello = #() { System.out.println("Hello!"); };
>
> #(String: void) printName = #(String name) { System.out.println(name); };
>
> #(String: int throws ParseException) parseInt = #(String s: int i) {
> i = DecimalFormat.getIntegerInstance().parse(s).intValue();
> };
>
> #(int, int: int) add = #(int a, int b: int c) { c = a+b; };
>
>
> Notice that "no return statements were harmed in this presentation" ;-)
>
> And using this syntax they don't have to be harmed, ever. If "Block" is
> prefixed with a label:
>
> LambdaExpression:
> '#' '(' FormalParametersList_opt ResultParameter_opt ')' Label_opt Block
>
> Label:
> ':' Identifier
>
> Then "return" from lambda becomes a familiar "break label". For 1st JDK7
> release, non-local returns/breaks/continues could be disallowed but the
> path to future transparent lambda would stay open...
>
Do you mean to return from closure as soon as you assign to the result
parameter? If yes, it is not transparent. If no, how do you want to return
early?
Z.
--
Zdenek Tronicek
FIT CTU in Prague
More information about the lambda-dev
mailing list