digitalmars.D.learn - Why is this pure?
- Shachar (13/13) Aug 24 2014 The following program compiles, and does what you'd expect:
- Alex =?UTF-8?B?UsO4bm5l?= Petersen (2/15) Aug 24 2014 http://klickverbot.at/blog/2012/05/purity-in-d/
The following program compiles, and does what you'd expect: struct A { int a; } pure int func( ref A a ) { return a.a += 3; } As far as I can tell, however, it shouldn't. I don't see how or why func can possibly be considered pure, as it changes a state external to the function. What am I missing? Or is this just a compiler bug? Shachar
Aug 24 2014
On Monday, 25 August 2014 at 06:27:00 UTC, Shachar wrote:The following program compiles, and does what you'd expect: struct A { int a; } pure int func( ref A a ) { return a.a += 3; } As far as I can tell, however, it shouldn't. I don't see how or why func can possibly be considered pure, as it changes a state external to the function. What am I missing? Or is this just a compiler bug? Shacharhttp://klickverbot.at/blog/2012/05/purity-in-d/
Aug 24 2014