Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Joshua Cranmer Newsgroups: comp.lang.java.programmer Subject: Re: new Java lambda syntax Date: Sun, 11 Sep 2011 17:07:56 -0500 Organization: A noiseless patient Spider Lines: 36 Message-ID: References: <9j3vj8-aqe.ln1@news.simpsonst.f2s.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 11 Sep 2011 22:08:30 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="WpcHJSul77m+zlbR9GVqkA"; logging-data="18624"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+RekEB27pRLJrHvyVDqEI8+/XVoa4i5d8=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20110902 Thunderbird/6.0.2 In-Reply-To: Cancel-Lock: sha1:G/0jftyZayz897FRuial42KRWMg= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:7830 On 9/11/2011 2:14 PM, Steven Simpson wrote: > On 11/09/11 19:08, BGB wrote: >> I would have also liked to see lexical variable capture. >> FFS, I added this (along with closures) to a C compiler before, can't >> be too hard > > At this stage, I don't think the issue is how, but whether/when to > permit it. There are other issues like does it capture the value or does it use the same variable. e.g., what would this produce: List runners = new LinkedList(); for (int i = 0; i < 10; i++) { runners.add(() => { System.out.println("Value of i is " + i); }); } for (Runnable r : runners) { r.run(); } Should you see 0..9 or 10 repeated 10 times? > For invocations, having to type obj.run() instead of obj() is hardly > onerous. Plus, invocations will be much rarer than lambda declarations. > Also note that the invocation site is unaware of whether the object is a > lambda. Also, note the (slight) benefits of explicitly saying what you are doing. You might choose, reasonably, to call the callback parameter for an asyncForEach function `block', at which point the functional call specification becomes block(value), which can be visually ambiguous as to what it's doing. block.call(value) is clearer, on the other hand. -- Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth