On Thu, 18 Jun 2009 00:32:20 +0400, Jeroen Dirks <[email protected]> wrote:

Does anyone know the answer to this D related question on SO?

http://stackoverflow.com/questions/1008803/how-to-use-pure-in-d-2-0/

There needs to be a way to tell that addMsg doesn't access global variables.

One of the solutions is to add one more annotation (I call it impure here, because it is an exact opposite of pure):

void foo() // doesn't access globals, fine to call inside pure functions
{
}

void bar() // fails to compile, accesses global state but doesn't have proper annotation
{
    errno = 42;
}

impure void bar() // fine
{
    errno = 42;
}

But there might be a problem: calling impure function makes your function impure, too, so it's viral.

Another solution is... remove global variables entirely! No globals - no problems :)

Reply via email to