Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #7987

Re: new Java lambda syntax

From Tom Anderson <twic@urchin.earth.li>
Newsgroups comp.lang.java.programmer
Subject Re: new Java lambda syntax
Date 2011-09-13 21:29 +0100
Organization Eindhoven University of Technology
Message-ID <alpine.DEB.2.00.1109132120070.343@urchin.earth.li> (permalink)
References (6 earlier) <tsdvj8-vbg.ln1@news.simpsonst.f2s.com> <j4jbgt$i60$1@dont-email.me> <j4m6o0$t69$1@dont-email.me> <j4meun$99r$1@dont-email.me> <j4o9rt$i0g$1@dont-email.me>

Show all headers | View raw


On Tue, 13 Sep 2011, Daniele Futtorovic wrote:

> On 13/09/2011 04:24, Joshua Cranmer allegedly wrote:
>> On 9/12/2011 7:00 PM, Daniele Futtorovic wrote:
>>> On 12/09/2011 00:07, Joshua Cranmer allegedly wrote:
>>>
>>>> List<Runnable>  runners = new LinkedList<Runnable>();
>>>> for (int i = 0; i<  10; i++) {
>>>>    runners.add(() =>  { System.out.println("Value of i is " + i); });
>>>> }
>>>> for (Runnable r : runners) {
>>>>    r.run();
>>>> }
>>>
>>> Beg your pardon, I haven't followed this issue as closely as I 
>>> probably have should, but does this all mean lambdas are always 
>>> Runnables? Never Callable<T>s? IOW, no return values?
>>
>> No, I just opted for Runnable here because it was simple.
>
> Okay, so you can have a lambda returning a value? Steve Simpson's statement:
>
>> There's no (...) long jumps (break, continue, return, throw)
>
> seemed to contradict that, as did Tom's about the "Gafterist nonsense"
> (<3), seeing how Gafter et al.'s proposal contained return values, IIRC.

Brachaism-Gafterism is the CANCER THAT IS KILLING JAVA!!

> I mean, if they cannot return values, I'm a bit at a loss understanding 
> how they'll be the nec plus ultra for parallel computing... you'd 
> publish results to a shared queue, I suppose, but that's a bit unhandy.

A lambda can return a value. It just can't return it from another method.

You will be able to say (something like):

Callable<String> one = () => {return "uno";};
String s = one.call();
assert s.equals("uno");

You will not be able to say:

String thisIsWhatBGGAWanted() {
 	Callable<String> one = () => {return "uno";};
 	one.call();
 	return "ein";
}
String s = thisIsWhatBGGAWanted();
assert s.equals("uno");

Basically, lambdas can be either method-like (they return values from 
themselves) or statement-like (they return values from their enclosing 
methods). Lambdas are method-like in all the current dynamic languages 
(AFAIK - they certainly are in Smalltalk, Python and Javascript). The BGGA 
proposal (and i remember this coming from Gafter in particular, BICBW) 
would have made them statement-like.

The rationale was that enclosing any given wodge of code in a lambda 
definition immediately followed by an invocation of that lambda would not 
change the behaviour of the code. This seemed dubious to me, and would 
have led to very weird programming experiences. It would, though, have 
enabled a wider range of funky control structures implemented on top of 
lambdas, which some people are very keen on.

tom

-- 
Oh well, one plays these games and the scones did look rather
delicious. -- Stephen Fry

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

new Java lambda syntax markspace <-@.> - 2011-09-08 13:19 -0700
  Re: new Java lambda syntax Roedy Green <see_website@mindprod.com.invalid> - 2011-09-08 15:18 -0700
    Re: new Java lambda syntax Arne Vajhøj <arne@vajhoej.dk> - 2011-09-08 18:27 -0400
    Re: new Java lambda syntax BGB <cr88192@hotmail.com> - 2011-09-08 15:40 -0700
      Re: new Java lambda syntax Arne Vajhøj <arne@vajhoej.dk> - 2011-09-08 19:27 -0400
        Re: new Java lambda syntax BGB <cr88192@hotmail.com> - 2011-09-08 16:29 -0700
          Re: new Java lambda syntax Arne Vajhøj <arne@vajhoej.dk> - 2011-09-08 19:48 -0400
          Re: new Java lambda syntax Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-09-08 17:56 -0700
            Re: new Java lambda syntax BGB <cr88192@hotmail.com> - 2011-09-08 22:23 -0700
    Re: new Java lambda syntax "Nasser M. Abbasi" <nma@12000.org> - 2011-09-08 16:41 -0700
    Re: new Java lambda syntax Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-09-08 20:50 -0500
  Re: new Java lambda syntax bugbear <bugbear@trim_papermule.co.uk_trim> - 2011-09-09 09:33 +0100
  Re: new Java lambda syntax Tom Anderson <twic@urchin.earth.li> - 2011-09-10 14:48 +0100
    Re: new Java lambda syntax Steven Simpson <ss@domain.invalid> - 2011-09-10 16:17 +0100
      Re: new Java lambda syntax Tom Anderson <twic@urchin.earth.li> - 2011-09-11 13:06 +0100
        Re: new Java lambda syntax Steven Simpson <ss@domain.invalid> - 2011-09-11 17:18 +0100
          Re: new Java lambda syntax BGB <cr88192@hotmail.com> - 2011-09-11 11:08 -0700
            Re: new Java lambda syntax Steven Simpson <ss@domain.invalid> - 2011-09-11 20:14 +0100
              Re: new Java lambda syntax BGB <cr88192@hotmail.com> - 2011-09-11 14:08 -0700
              Re: new Java lambda syntax Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-09-11 17:07 -0500
                Re: new Java lambda syntax BGB <cr88192@hotmail.com> - 2011-09-11 16:18 -0700
                Re: new Java lambda syntax Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2011-09-13 02:00 +0200
                Re: new Java lambda syntax Arne Vajhøj <arne@vajhoej.dk> - 2011-09-12 20:59 -0400
                Re: new Java lambda syntax Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-09-12 21:24 -0500
                Re: new Java lambda syntax Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2011-09-13 21:04 +0200
                Re: new Java lambda syntax Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-09-13 15:22 -0500
                Re: new Java lambda syntax Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2011-09-13 23:25 +0200
                Re: new Java lambda syntax Tom Anderson <twic@urchin.earth.li> - 2011-09-13 21:29 +0100
                Re: new Java lambda syntax Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2011-09-13 23:26 +0200
                Re: new Java lambda syntax supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-09-13 20:25 -0400
                Re: new Java lambda syntax Tom Anderson <twic@urchin.earth.li> - 2011-09-15 21:58 +0100
                Re: new Java lambda syntax Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-09-13 21:36 -0500
                Re: new Java lambda syntax supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-09-13 22:49 -0400
                Re: new Java lambda syntax "supercalifragilisticexpialadiamaticonormalizeringelimatisticantations" <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-09-14 02:49 -0400
                Re: new Java lambda syntax supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-09-14 03:01 -0400
                Re: new Java lambda syntax "winkleMeister" <..00@00.00.00.1> - 2011-09-14 09:59 +0000
                Re: new Java lambda syntax supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-09-15 10:16 -0400
                Re: new Java lambda syntax supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-09-14 06:40 -0400
                Re: new Java lambda syntax supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-09-15 10:16 -0400
                Re: new Java lambda syntax lightworker <etts@0n.org.null> - 2011-09-16 01:57 +0000
                Re: new Java lambda syntax thoolen <th00len@th0lenbot.thorium> - 2011-09-15 22:41 -0400
                Re: new Java lambda syntax Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-09-14 06:29 -0300
                Re: new Java lambda syntax BGB <cr88192@hotmail.com> - 2011-09-14 07:40 -0700
                Re: new Java lambda syntax Lew <lewbloch@gmail.com> - 2011-09-14 08:01 -0700
                Re: new Java lambda syntax BGB <cr88192@hotmail.com> - 2011-09-14 14:50 -0700
                Re: new Java lambda syntax Lew <lewbloch@gmail.com> - 2011-09-14 18:02 -0700
                Re: new Java lambda syntax BGB <cr88192@hotmail.com> - 2011-09-14 21:08 -0700

csiph-web