On Saturday, 3 August 2013 at 21:19:35 UTC, monarch_dodra wrote:
On Saturday, 3 August 2013 at 19:07:49 UTC, Meta wrote:
On Saturday, 3 August 2013 at 16:47:52 UTC, Timon Gehr wrote:
On 08/03/2013 05:59 PM, monarch_dodra wrote:
One last question: Pointers.
int get(int* p) pure
{
return *p;
}
void main()
{
int i = 0;
auto p = &i;
get(p);
}
Here, get, to me, is obviously not pure, since it depends on
the state
of the global "i". *Where* did "get" go wrong? Did I simply
"abusively"
mark get as pure? Is the "pure" keyword's guarantee simply
"weak"?
...
Yes, it's weak.
It depends on whether you think a pointer dereference is pure
or not (I don't know the answer). That aside, as long as get
doesn't modify the value at *p or change what p points to,
this is strongly pure (i.e., the academic definition of
purity).
Thank the 3 of you for your answers. I think I had a wrong
preconception of what pure is. I think this cleared most of it
up.
Is there anywhere formal defining D's pure (weak vs strong etc.)?
A page in the wiki perhaps?
Imagine someone new coming to D and being confused by what our
purity system is. It would suck to only be able to give an ad-hoc
answer or link them to a previous discussion.
I would offer but I don't really understand it myself.