Pure delegate not quite pure?

Tofu Ninja via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jun 28 02:19:15 PDT 2015


module main;
import std.stdio;
void main(string[] args)
{
	auto d = foo();
	writeln(d()); // prints 25
}

auto foo()
{
	int x = 4;
	pure int delegate() d = delegate()
	{
		return x*x;
	};
	writeln(d()); // prints 16
	x = 5;
	writeln(d()); // prints 25
	return d;
}

I can see that after foo returns, then d will truly be pure as x 
will no longer be modifiable, but just before that, it seems d is 
not actually pure. Is this the intended behavior?


More information about the Digitalmars-d-learn mailing list