Do pure functions solve the "return const" problems?
Janice Caron
caron800 at googlemail.com
Fri Apr 4 23:15:32 PDT 2008
On 05/04/2008, Christopher Wright <dhasenan at gmail.com> wrote:
> Still, there shouldn't be any difference between
> out parameters and return values.
I think there should. Suppose f is declared:
pure int f(out int n);
Now consider the expression:
f(x) + f(x)
See the problem?
Expressed in purely functional terms, you would have to rewrite the code as:
alias Tuple!(int,int) Pair;
pure Pair f();
pure Pair g(Pair lhs, Pair rhs);
where g() takes the place of +. Now the expression becomes
g(f(),f())
which doesn't suffer the same problem.
More information about the Digitalmars-d
mailing list