Do pure functions solve the "return const" problems?
Christopher Wright
dhasenan at gmail.com
Sat Apr 26 21:56:21 PDT 2008
Bruno Medeiros wrote:
> Christopher Wright wrote:
>>
>> You're not getting this.
>>
>> int f (out int i);
>> int x;
>> int y = f(x) + f(x);
>>
>> This already works. Why couldn't pure functions do this? You can't
>> tell me. You aren't arguing. You are just stating that the compiler
>> can't do something that it already does. If the compiler supports
>> memoization of pure functions based on parameters, it could easily
>> exclude out parameters. If the compiler requires that all inputs to a
>> pure function be scope invariant, out parameters could be excluded
>> from that requirement.
>
> Changing an out parameter is a side effect. Pure functions cannot have
> side effects (ie, they cannot change state outside of their scope). If
> they did, it would break the purpose for which they are intended.
> What more is there to get?
An out parameter is a return value. What else is there to get?
More information about the Digitalmars-d
mailing list