transparent lambda

Neal Gafter neal at
Tue Dec 29 12:02:56 PST 2009

On Tue, Dec 29, 2009 at 11:50 AM, Mark Mahieu <markmahieu at>wrote:

>   However, I don't think you've perfected it yet.  Two issues come to mind:
>    1. I'm afraid there might be some ambiguity with function types.
>    Specifically, is "#X() Y" the declaration of a variable Y of function type
>    "#X()", or is it a lambda labelled X whose value is Y?  Adding mandatory
>    parens around the expression part of a lambda expression might help.
> The JLS already declares that statements may be prefixed by a label, so
> isn't there already a natural position for the label to occur in a
> StatementLambda?
> #() label: { /* block */ }
> That doesn't seem too bad to me.

That's ambiguous with an expression lambda in the middle part of a ?:
expression (because "#()ID" looks like an expression lambda).  Requiring
parens in an expression lambda might help.

>    1. I think the labelled yield syntax could be improved.  I suspect
>    something like "yield label : expression;" would be easier on the eyes.
> Yes that looks ok.  There might be a slight readability issue when the
> expression contains a conditional ?: operator, but that's probably no big
> deal.
> Presumably you'd also want to support using this in lambdas with a void
> result type, which might then be as simple as:
> yield label;
> With a new 'yield' keyword, I think that gives us a nice (syntactic)
> relationship with the use of labels and break/continue.  It's notable that
> it would not work out so well with 'return'.

Not so well in the sense that the colon would be required: "return
label:;".  On the other hand, labeled returns could be used with the method
name as a label too.

-------------- next part --------------
An HTML attachment was scrubbed...

More information about the closures-dev mailing list