Transitive const sucks (pure)
Ingo Oeser
ioe-news at rameria.de
Wed Sep 12 17:34:36 PDT 2007
Bruce Adams wrote:
> I not sure whether pure functions can modify class variables.
I hope not!
> The
> presentation states that they can't modify anything reachable through
> their arguments.
They are like mappings (e.g y = f(x) ) in math.
If you write sth. like this:
b = foo;
for(i = 0; i < rand_range(1,1000); i++) {
a = pure_func(b);
}
writefln("%s", a);
b will still contain foo and a will always have the same value in every
program run. pure_func will only be called once here. This is the possible
compiler optimisation, if pure_func() is a pure function.
Best Regards
Ingo Oeser
More information about the Digitalmars-d
mailing list