Function literals and lambda functions

Russel Winder russel at russel.org.uk
Sun Mar 6 08:04:25 PST 2011


On Sun, 2011-03-06 at 10:08 -0500, bearophile wrote:
> Russel Winder:
> 
> >         reduce ! ( ( a , b ) { return a + b ; } ) ( 0.0 , outputData ) 
> > 
> > works just fine, but:
> > 
> >         reduce ! ( function double ( double a , double b ) { return a + b ; } ) ( 0.0 , outputData )
> 
> 
> import std.stdio, std.algorithm, std.range;
> 
> void main() {
>     auto outputData = iota(1.0, 10.0);
> 
>     auto r1 = reduce!((a, b){ return a + b; })(0.0, outputData);
>     writeln(r1);
> 
>     auto r2 = reduce!((double a, double b){ return a + b; })(0.0, outputData);
>     writeln(r2);
> 
>     auto r3 = reduce!("a + b")(0.0, outputData);
>     writeln(r3);
> 
>     auto r4 = reduce!q{a + b}(0.0, outputData);
>     writeln(r4);
> 
>     auto r5 = reduce!q{a + b}(outputData); // not exactly the same
>     writeln(r5);
> }
> 
> Bye,
> bearophile

So why does:

        reduce ! ( function double ( double a , double b ) { return a + b ; } ) ( 0.0 , outputData )

fail?  It implies that a function literal and a lambda are significantly
different things as far as the compiler is concerned.

-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder at ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel at russel.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20110306/37b92946/attachment.pgp>


More information about the Digitalmars-d mailing list