Re: A question about purity

2011-09-14 Thread Steven Schveighoffer
On Tue, 13 Sep 2011 07:43:55 -0400, bearophile wrote: 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 stru

Re: A question about purity

2011-09-13 Thread Jonathan M Davis
On Tuesday, September 13, 2011 07:43:55 bearophile wrote: > 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 bi

Re: A question about purity

2011-09-13 Thread Kagamin
bearophile Wrote: > 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? Weakly pure function

Re: A question about purity

2011-09-13 Thread Christophe
bearophile , dans le message (digitalmars.D.learn:29490), a écrit : > 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 th

Re: A question about purity

2011-09-13 Thread bearophile
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 avoi

Re: A question about purity

2011-09-12 Thread Jonathan M Davis
On Monday, September 12, 2011 15:24 bearophile wrote: > A D2 program: > > > struct Foo { > int x; > static int y; > pure void foo1() { > this.x++; > } > static pure void foo2() { > Foo.y++; // line 8, error > } > } > void main() {} > > > With DMD 2.055 it gives at compile-time: > test.d(8): Err

A question about purity

2011-09-12 Thread bearophile
A D2 program: struct Foo { int x; static int y; pure void foo1() { this.x++; } static pure void foo2() { Foo.y++; // line 8, error } } void main() {} With DMD 2.055 it gives at compile-time: test.d(8): Error: pure function 'foo2' cannot access mutable sta