Do pure functions solve the "return const" problems?

Christopher Wright dhasenan at gmail.com
Sun Apr 27 09:15:24 PDT 2008


Janice Caron wrote:
> On 27/04/2008, Christopher Wright <dhasenan at gmail.com> wrote:
>>  An out parameter is a return value. What else is there to get?
> 
> An out parameter is global state. Sometimes literally:
> 
>     void foo(out int x, int y) { x = y; }
> 
>     foo(globalVariable, 3);

Then the calling function isn't pure!
I could also do:
int foo(int y) { return y; }
globalVariable = foo(3);

> Also, as has been repeatedly pointed out, one of the benefits of pure
> is that given an expression like
> 
>     f(x,y) + g(x,y)
> 
> the compiler is free to evaluate f first then g, or g first then f, at
> its discression. It is also free not to call either of these functions
> at all if it has a previously cached result handy. Out parameters must
> be forbidden, or those assumptions fail.

Then so must return values!



More information about the Digitalmars-d mailing list