Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: markspace <-@.> Newsgroups: comp.lang.java.programmer Subject: new Java lambda syntax Date: Thu, 08 Sep 2011 13:19:22 -0700 Organization: A noiseless patient Spider Lines: 53 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 8 Sep 2011 20:19:38 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="XjIWM99mD7Ijfdu600oVPA"; logging-data="30816"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19rrfL9E9aFlM0hnxRaPhoL1oop53d3qeU=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2 Cancel-Lock: sha1:sg9qo2XQRcS61LXB1ebPRd/jrH0= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7719 Just thought some folks might be interested in this: Date: Thu, 08 Sep 2011 16:07:03 -0400 From: Brian Goetz To: "lambda-dev@openjdk.java.net" "This just in: the EG [Expert Group] has (mostly) made a decision on syntax. After considering a number of alternatives, we decided to essentially adopt the C# syntax. We may still deliberate further on the fine points (e.g., thin arrow vs fat arrow, special nilary form, etc), and have not yet come to a decision on method reference syntax. The C# syntax is: lambda = ArgList Arrow Body ArgList = Identifier | "(" Identifier [ "," Identifier ]* ")" | "(" Type Identifier [ "," Type Identifier ]* ")" Body = Expression | "{" [ Statement ";" ]+ "}" Here are some examples of lambda expressions using this syntax: x => x + 1 (x) => x + 1 (int x) => x + 1 (int x, int y) => x + y (x, y) => x + y (x, y) => { System.out.printf("%d + %d = %d%n", x, y, x+y); } () => { System.out.println("I am a Runnable"); } The decision to choose this syntax was twofold: - The syntax scores "pretty well" on most subjective measures (though has cases where it looks bad, just like all the others do). In particular, it does well with "small" lambdas that are used as method arguments (a common case), and also does well with large (multi-statement) lambdas. - Despite extensive searching, there was no clear winner among the alternatives (each form had some good aspects and some really not very good aspects, and there was no form that was clearly better than the others). So, we felt that it was better to choose something that has already been shown to work well in the two languages that are most like Java -- C# and Scala -- rather than to invent something new. A compiler implementation should be available soon."