Anonymous function syntax
Rory McGuire
rjmcguire at gmail.com
Thu Sep 22 00:46:23 PDT 2011
Perhaps bearofile refers to this:
import std.stdio;
string getit(alias runme)() {
return runme("b","da");
}
string getit2(string delegate(string,string) dg) {
return dg("b", "da");
}
void main() {
writefln("this is a %s", getit!((a,b){ return "lam"~a~b; })());
/+writefln("this is a %s too", getit2((a,b){ return "lam"~a~b; }));
/*lambdas.d(13): Error: undefined identifier a
lambdas.d(13): Error: undefined identifier b
lambdas.d(13): Error: function lambdas.getit2 (string
delegate(string, string) dg) is not callable using argument types (_error_
delegate(_error_, _error_))
lambdas.d(13): Error: cannot implicitly convert expression
(__dgliteral4) of type _error_ delegate(_error_, _error_) to string
delegate(string, string)
*/
+/
writefln("this is a %s too", getit2((string a, string b) { return
"lam"~a~b; }));
}
Cheers,
Rory
On Thu, Sep 22, 2011 at 12:50 AM, Andrei Alexandrescu <
SeeWebsiteForEmail at erdani.org> wrote:
> On 9/21/11 5:29 PM, bearophile wrote:
>
>> Walter Bright:
>>
>> D
>>> (a,b) { return a + b; }
>>>
>>
>> In D to define a true lambda you need types too:
>> auto f = (int a,int b){ return a + b; };
>>
>
> No.
>
> Andrei
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20110922/a8d11811/attachment.html>
More information about the Digitalmars-d
mailing list