Do pure functions solve the "return const" problems?

Bruno Medeiros brunodomedeiros+spam at com.gmail
Sat Apr 26 15:10:36 PDT 2008


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?


-- 
Bruno Medeiros - Software Developer, MSc. in CS/E graduate
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list