Function types syntax

Peter Levart peter.levart at marand.si
Wed Jan 27 07:27:39 PST 2010


On Wednesday 27 January 2010 08:41:29 John Rose wrote:
> #(String)->int stringLength;
> 
> stringLength = #(String s) int length: {
>   if (s == null) break length = -1;
>   length = s.length();
>   };
> 
> P.S.  That last example of stringLength could be (I think should be) viewed as the combination of two independent language features, an expression-lambda of the form #(ARGS) EXPR and a block-let-expression of the form TYPE VAR: BLOCK, equipped with a value-bearing break statement: break VAR = EXPR;
> 
> With such a block-let-expression, there would be no need to define statement-lambdas of the form #(ARGS) BLOCK, except for void-valued lambdas.
> 

Would block-let-expression also declare a variable with the scope outside the block or only inside?

If it is only expression and not a variable (local, field) declaration then it realy only has utility in conjunction with expression lambdas. You would have to write the following to assign it's value to a real variable:

int length = int len: { .... };

I doubt it would be usefull as an argument to a method invocation, since code to compute argument values traditionaly preceeds the invocation.

What about the following:

VariableDeclarator:
    VariableDeclaratorId : Block

And then 3 forms of lambdas:

LambdaExpression:
   #(FormalParameterList_opt) Expression
   #(FormalParameterList_opt) Block   // only for void lambdas, no return necessary, optionaly prefix block with a label
   #(FormalParameterList_opt) VariableModifiers Type VariableDeclarator


Regards, Peter


More information about the lambda-dev mailing list