Problem about lambda expressions

Tongzhou Li zhangsongcui at hotmail.com
Wed Mar 28 01:22:24 PDT 2012


On Tuesday, 27 March 2012 at 15:21:57 UTC, Kenji Hara wrote:
> On Tuesday, 27 March 2012 at 13:42:30 UTC, Tongzhou Li wrote:
>> Hello again! I'm learning D, and I encountered a problem.
>> I tried this code:
>> http://ideone.com/hkpT6
>> It works well. (Have no idea why codepad.org failed to compile 
>> it)
>> I tried to write a lambda instead of function f, but I got 
>> nothing printed.
>> Did I make something wrong?
>> Compiler used: DMD32 D Compiler v2.058 (Win7 SP1 x64)
>> Sorry for my poor English :)
>
> (obj x, int a0, int a1) => { x.setxxx(a0); x.setyyy(a1); }
>
> This lambda expression returns *a delegate has no parameter*.
> Instead:
>
> (obj x, int a0, int a1) => (x.setxxx(a0), x.setyyy(a1))
>
> or:
>
> (obj x, int a0, int a1){ x.setxxx(a0); x.setyyy(a1); }

I understood. But why it compiles instead of giving an error? 
What does the complier do when I write the wrong code?


More information about the Digitalmars-d-learn mailing list