A question about purity

bearophile bearophileHUGS at lycos.com
Tue Sep 13 04:43:55 PDT 2011


Jonathan M Davis:

> However, Foo.y is not encapsulated 
> by a strongly pure function at all. Other functions can alter alter it. So, it 
> breaks purity.

Thank you for your explanation :-)

So, let's change the situation a bit. If the struct Foo is the only thing present in a module (to avoid someone to touch its private members), and the y field is "private static" only foo2 is able to touch it. In this case isn't foo2 weakly pure?


struct Foo {
    private static int y;
    static pure void foo2() {
        Foo.y++;
    }
}
void main() {}


Bye,
bearophile


More information about the Digitalmars-d-learn mailing list