On Tue, 16 Dec 2008 12:28:43 -0800, Simen Kjaeraas
<[email protected]> wrote:
On Tue, 16 Dec 2008 18:58:47 +0100, Robert Jacques <[email protected]>
wrote:
On Mon, 15 Dec 2008 17:48:21 -0500, mastrost <[email protected]>
wrote:
In this example, myPureFunction looks like a pure function, does it?
No it doesn't
So this does not seem pure to you?
int myPureFunction(int x) {
return x;
}
Short answer: That's a function, not a delegate and without a 'pure' tag
it's unreasonable for the complier to know it's logically pure.
Long answer: Your original arguement was:
But the fact is that when returning a delegate, its closure freezes
forever and so
behaves like a local variable and not like a global variable by respect to
the
delegate :
Which I read to mean that a returned delegate is inherently pure. On a
second read, I think you mean that the closure heap variables may be
treated as immutable once a delegate is returned if the delegate doesn't
mutate them. While an interesting observation, it too is easily broken:
int delegate() impure;
int delegate() getPureFunction(int x){
int bar(){
return x;
}
int foo() {
return x++;
}
impure = foo; // The closure may not be considered immutable since
'x' escapes
return &bar;
}