Proposal: Relax rules for 'pure'

sclytrack sclytrack at fake.com
Wed Sep 22 13:42:09 PDT 2010


> weaklypure void reverse(int[] x)
> {
>     for(int i = 0; i * 2 < x.length; i++)
>         swap(x[i], x[$-1-i]);
> }
> pure int foo(const(int)[] x)
> {
>      auto x2 = x.dup;
>      reverse(x2);
>      // do some calculation on x2
>      ...
>      return calculation;
> }

noglobal void reverse(MyClass x)
{
  x.text = "";
}

So weakly-pure should not access global stuff. But that is harder
to track by the compiler with mutable parameters.

Or weakly-pure is only noglobal when called in pure routines, because of the
immutable barrier.

Unwritten contract, not checked by the compiler?  (Like property getters shouldn't
modify the "state" of the object.)



More information about the Digitalmars-d mailing list