Function literals and lambda functions

Russel Winder russel at russel.org.uk
Sun Mar 6 09:03:35 PST 2011


On Sun, 2011-03-06 at 17:45 +0100, Simen kjaeraas wrote:
> Russel Winder <russel at russel.org.uk> wrote:
> 
> > 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.
> 
> Well, they are. One is a delegate literal, the other a function literal.
> Delegates may be closures, functions may not.

Hummm... good point.  If you s/function/delegate/ in the above it works
fine

> That said, the above looks like it should work, and I'm not sure why it
> doesn't.

Obviously (now :-) because the context requires a delegate not a
function -- it is just that the error message doesn't say that in terms
that don't relate to the code they relate to the realization within the
compiler.

Is this use of the term delegate consistent with the C# idea of
delegate?  It certainly is not consistent with the use in Groovy and
other dynamic languages. 

-- 
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/afe45e27/attachment.pgp>


More information about the Digitalmars-d mailing list