# transparent lambda

Peter Levart peter.levart at gmail.com
Fri Jan 8 13:29:35 PST 2010

```On Fri, Jan 8, 2010 at 5:52 PM, Neal Gafter <neal at gafter.com> wrote:

> On Fri, Jan 8, 2010 at 2:02 AM, Peter Levart <peter.levart at marand.si>wrote:
>
>> I have a feeling that this might be it (provided that it is acceptable).
>> With this we can satisfy both camps:
>
>
> It's not too bad, but I have two concerns.
>
> First, I think the ambiguities around the trinary expression are a little
> hairy.
>

You mean this:

a ? b : (s;) : c

Well, since (s;) can not be parsed as an expression (again because we keep
statement and expression syntaxes separate), it can only be parsed as:

a ? (b : (s;)) : c

But it is hairy for a human eye. I imagine this does not present to much of
a problem, since one would rather write this example as:

b:( if (a) s; break b : c; )

But let's see if it can change the meaning if one removes a single ';' :

a ? b : (s) : c

if s is statement expression then (s) is expression and we have:

(a ? b : (s)) : c

which is clearly a syntax error.

Second, when put together with expression lambdas, it is a little noisy.
>

It is, but again I assume one would use this form only if the logic of the
lambda expression was not trivial, so it would be written in multiple lines.
For example (when label is part of lambda):

*#int(int,int) zeroesComeFirst = #label(int x, int y) (*
*    if (x == y) break label : 0;*
*    if (x == 0) break label : -1;*
*    if (y == 0) break label : 1;*
*    break label : (x < y) ? -1 : 1; *
*)*

or when it is part of block expression:

*#int(int,int) zeroesComeFirst = #(int x, int y) label:(*
*    if (x == y) break label : 0;*
*    if (x == 0) break label : -1;*
*    if (y == 0) break label : 1;*
*    break label : (x < y) ? -1 : 1; *
*)*
*
*
not to much of a difference, is it?

> I didn't do anything like this in CfJ 0.6b, because it isn't really so bad
> just doing it yourself.
>
Is there really a camp clamoring for a lambda form that is both
> transparent and which has an early exit?
>

No, not nearly as big as the camp clamoring for lambda with semantics of
anonymous inner classes, but it is nice to know that the path to transparent
lambda with early exit is open through expression lambdas in case there is a
demand and statement lambda syntax is used for non-transparent lambda.

Regards, Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/closures-dev/attachments/20100108/7958d4c3/attachment.html
```