transparent lambda
John Rose
John.Rose at Sun.COM
Wed Jan 6 23:39:44 PST 2010
On Jan 6, 2010, at 11:04 PM, Neal Gafter wrote:
> The block expressions of Cfj 0.6b
> <http://www.javac.info/closures-v06b.html> are an approach related to
> your let expressions
Right, I noticed that document, which defines (S;E) as (what I called) a let-statement.
(I also remember seeing the similar {S;E} for a similar purpose in some 2006 closure conversations, but { S; E } is too easily mistaken for, and is one typo away from, { S; E; }. Using round parens as you do makes the syntax more distinctive. But then it starts to look like an argument list, and to take up syntax room traditionally used for tuples.)
> but much simpler because they are orthogonal to
> lambdas.
Sure, that was my point: Either 0.6b block expressions or "backward let expressions" (pending a better name) are independent of but synergistic with lambdas. Two smaller synergistic features are better than one omnibus feature.
> For labeled lambda yields, the nicest thing I've seen so far looks
> something like this:
>
> #(int,int) myClosure = #label(int arg1, int arg2) { ... break label :
> value; ... }
I like that. It doesn't require mentioning the return type. Having a named return variable doesn't add much if you do everything with value-bearing labeled break. (The main thing you miss is the chance to define a default value up front.) The important thing is that there is a label in the mix.
(IIRC, Groovy has a value-bearing break like that.)
Maybe, instead of 0.6b block expressions, a let-expression could be like a labeled lambda without formals:
#label{ ... break label : value; ...}
Or, dispensing with the hash mark but requiring parentheses:
(label:{ ... break label : value; ...})
With no need for parens in most places, especially argument and initializer expressions:
foo(0, label:{ ... break label : value; ...}, 1)
int foo = label:{ ... break label : value; ...};
In any case, a header-ish thing like #label{...} or label:{...} makes let-expressions easily recognizable from the left, and the label makes it fairly easy to scan the body for return values.
Backfilling that into lambdas we would get:
#(formal...) #label{ ... break label : value; ...}
or:
#(formal...) label:{ ... break label : value; ...}
-- John
More information about the closures-dev
mailing list