On Tue, 22 Feb 2011 15:48:42 -0500, %u <wfunct...@hotmail.com> wrote:

D pure functions are significantly different than this definition
(as of recent times, when weak-pure was added).
Essentially, a pure function cannot access global variables.
However, it can access variables referred to via a member of the
object instance.
i.e. this is a valid pure function:
class C
{
   int x;
   pure void foo() { x++; }
}

I... did not know that. But even in that case, pure wouldn't make much
sense, because doing anything like freeing memory or closing a file
handle affects global variables (whether directly in the runtime or
indirectly in the OS)... right?

Freeing and allocating memory is fair game for pure functions. It is one of the only exceptions to the rule, because without the ability to allocate and free memory, functional programming is quite limited.

On closing a file, you couldn't close that file unless the function to close it was marked pure. I would *hope* that the C call to close a file was not marked as pure.

I wasn't advocating that destructors can be pure, I was just pointing out that the concept of pure has changed in recent times.

-Steve

Reply via email to