How to hand in a closure variable

Bienlein jeti789 at web.de
Mon Mar 24 09:40:54 PDT 2014


Hello,

I have some piece of code that compiles and runs fine:

void main(string[] args)
{	
	int a = 7;
	int delegate() dg = { return a + 3; };
	auto result = dg();
	writeln(result);
}

Now I want the closure (aka delegate) to have a closure variable:

int a = 7;
int delegate(int) dg = { value => return value + a + 3; };
auto result = dg(123);

Unhappily, the code above doesn't compile. Tried various things, 
looked for samples on the D hompepage and in the book by Çehreli, 
but had no luck.

Some hints appreciated.
Thanks, Bienlein


More information about the Digitalmars-d-learn mailing list