Optional brackets around lambda expression (was: Expecteddistribution of lambda sizes)

Gernot Neppert mcnepp02 at googlemail.com
Mon Jun 20 00:04:29 PDT 2011


Hi Reinier,

if I understand the draft specification (a.k.a "State of the lambda")
correctly, lambda expressions can only appear in contexts where a cast
or an assignment to a SAM-type follows the lambda expression
immediately.
Thus, your example of a String-concatenation expression containing a
lambda is somewhat irrelevant as it would not be allowed by the
proposed grammar.

To make the example valid, you'd have to apply a cast to a SAM type,
and I think we all agree that requiring parentheses around the lambda
before the cast is applied would be the natural thing to do. So the
example would become:

"" + (String2IntConverter)(#(String a) a.length() + 5)




2011/6/19 Reinier Zwitserloot <reinier at zwitserloot.com>:
> If all ambiguity must be avoided, all mathematical expressions would be very
> awkward; only 2-arg arithmatic would be legit as anything else is
> We could throw some curveballs out there and ask random java programmers
> what they think the precedence order would be, something like:
>
> "" + #(String a) a.length() + 5
>
>
> And ask them if this prints "Function(String)int5" or "Function(String)int".
> If I was a gambling man I'd guess that the (vast) majority of java
> programmers will correctly guess "Function(String)int".
>
>  --Reinier Zwitserloot
>
>
>
> On Fri, Jun 17, 2011 at 1:11 PM, <david.moss at ubs.com> wrote:
>
>>
>>
>> > As discussed in another thread; it's just like strawman, except
>> > the parentheses around the expression are optional. Thus,
>> > official strawman wants this:
>> >
>> > Comparable<String> comparator = #(a, b) (a.length() - b.length());
>> >
>> > and the paren-less variant lets you write this instead:
>> >
>> > Comparable<String> comparator = #(a, b) a.length() - b.length();
>>
>> Hi,
>>
>> Seems to me this is ambiguous; you could have the following situation,
>> for instance:
>>
>> String b = "some";
>> Comparable<String> comparator = #(a, b) a.length() - b.length();
>>
>> And not know whether it should be read as:
>>
>> String b = "some";
>> Comparable<String> comparator = (#(a, b) a.length()) - b.length();
>>
>> Or:
>>
>> String b = "some";
>> Comparable<String> comparator = (#(a, b) a.length() - b.length());
>>
>> Kind Regards,
>>
>> David.
>>
>> --
>>
>> David S. Moss
>> Stress Testing Tool Lead Developer
>> IT Risk
>> 1923 96757
>>
>> --
>>
>> Sent from my Dell Optiplex 745
>> Based on the present E-Mail exchange, and/or on the agreement reached
>> with you, respectively, UBS is entitled to contact you via insecure
>> E-Mail:
>> (a) E-Mails contain substantial risks such as lack of confidentiality,
>> manipulation of content and sender, misdirection, viruses etc. UBS
>> does not accept any liability for damages arising from use of
>> E-mail. Accordingly, UBS recommends to abstain from sending any
>> sensitive information via E-Mail, from forwarding the text received
>> when submitting reply E-Mails and recommends to manually capture the
>> E-Mail address in every instance. If you should wish to verify the
>> content of this message, please request a hard-copy version.
>> (b) In principle, UBS does not accept any (purchase) orders,
>> cancellation of orders or authorizations etc. via E-mail. If UBS
>> receives such E-Mails, UBS is not obliged to expressly decline them.
>> If you have received this E-Mail by mistake or do not wish to be
>> contacted by E-Mail in the future, you are kindly asked to inform UBS
>> accordingly. Any E-Mail received by mistake (including all its annexes)
>> needs to be destroyed and the content may not be forwarded nor disclosed
>> to any further persons.
>> c) This message is provided for informational purposes and should not be
>> construed as a solicitation or offer to buy or sell any securities or
>> related financial instruments.
>>
>> UBS reserves the right to retain all messages. Messages are protected
>> and accessed only in legally justified cases.
>>
>
>


More information about the lambda-dev mailing list