What is the meaning of this?
Peter Levart
peter.levart at marand.si
Mon Feb 1 00:16:44 PST 2010
On Sunday 31 January 2010 23:17:07 Lawrence Kesteloot wrote:
> On Sun, Jan 31, 2010 at 1:39 AM, Peter Levart <peter.levart at gmail.com> wrote:
> > #int(int) factorial = #fact(int i)(i == 0 ? 1 : i * (int) (fact.(i - 1)));
>
> That's where you'd want the optional return type to go. Better to just
> allow a reference to the "factorial" variable.
>
> For example, if the compiler can't deduce the return type above, then
> you'd write:
>
> #int(int) factorial = #int(int i)(i == 0 ? 1 : i * factorial.(i - 1));
>
I thought about that too. It would have to be a special case of local variable declarator, otherwise it could get complicated. For example, would you allow this:
#int(int) test(#int(int) func) {
func.(10);
return func;
}
...
final #int(int) factorial = test( #int(int i)(i == 0 ? 1 : i * factorial.(i - 1)) );
Besides, that forces you to declare a variable beforehand. One would want to specify a recursive lambda inline:
doSomethingWith( #fact(int i)(i == 0 ? 1 : i * (int)fact.(i - 1)) );
Explicit return type in lambda expressions is hopefully not needed or it can be specified elsewhere. The place between '#' and '(' for a Type has the same drawbacks in function type syntax as in lambda expression syntax - it is not perfect for composing 2nd order functions. As the following syntax is more readable for function types in that case:
FunctionType:
'#' '(' ParameterTypes_opt -> ReturnType Throws_opt ')'
The same could be made for lambda expressions:
LambdaExpression:
'#' '(' ParameterList_opt -> ReturnType_opt ')' Block
Regards, Peter
More information about the lambda-dev
mailing list