Fully transitive const is not necessary

Bill Baxter dnewsgroup at billbaxter.com
Tue Apr 1 12:47:55 PDT 2008


Janice Caron wrote:
> On 01/04/2008, Bill Baxter <dnewsgroup at billbaxter.com> wrote:
>>    // Hypothetical pure function with implicit/deduced constness
>>    pure int foo(Klass a) {
>>       scope b = new Klass;
>>       Klass[] x;
>>       x ~= a;
>>       x ~= b;
>>       random_shuffle(x);
>>       x[0].prop = 10;  // is this ok or not?
>>    }
> 
> Just for the record, random_shuffle() is not a pure function, and
> hence cannot be called from within a pure function.

Ah, good point.  So make it:

     x = pure_random_shuffle(x);

Still I think that points to an unnecessary restriction on pure functions.

A function that _only_ modifies its arguments can be safely called from 
a pure function when the data being passed is local to the pure 
function.  For example this should be fine:

     void inc(ref int x) { x++; }

     pure int pure_func() {  int x=0; inc(x); return x; }

--bb



More information about the Digitalmars-d mailing list