Function literals and lambda functions

Russel Winder russel at russel.org.uk
Sun Mar 6 06:03:31 PST 2011


OK, this one surprised me, all that remains is for me to find out why it
shouldn't have done:

        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 )

results in:

        pi_d2_sequentialMap.d(45): Error: function std.algorithm.reduce!(function double(double a, double b)
        {
        return a + b;
        }
        ).reduce!(double,Map!(partialSum,Tuple!(int,int,double)[])).reduce.__funcliteral1 cannot access frame of function pi_d2_sequentialMap.execute.__funcliteral1
        pi_d2_sequentialMap.d(45): Error: function std.algorithm.reduce!(function double(double a, double b)
        {
        return a + b;
        }
        ).reduce!(double,Map!(partialSum,Tuple!(int,int,double)[])).reduce.__funcliteral1 cannot access frame of function pi_d2_sequentialMap.execute.__funcliteral1

which I think qualifies for the label "incomprehensible".  Not to
mention repetitious.


PS  If you ask why not:

        reduce ! ( "a+b" ) ( 0.0 , outputData )
        
I find this somehow unacceptable.  It's the string, its not a function.
Fine, my problem, but that still leaves the above.
-- 
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/b3622afa/attachment-0001.pgp>


More information about the Digitalmars-d mailing list