Problem about lambda expressions

Kenji Hara k.hara.pg at gmail.com
Tue Mar 27 08:21:55 PDT 2012


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); }



More information about the Digitalmars-d-learn mailing list