DMD 1.038 and 2.022 releases
Robert Jacques
sandford at jhu.edu
Tue Dec 16 15:39:00 PST 2008
On Tue, 16 Dec 2008 12:28:43 -0800, Simen Kjaeraas
<simen.kjaras at gmail.com> wrote:
> On Tue, 16 Dec 2008 18:58:47 +0100, Robert Jacques <sandford at jhu.edu>
> wrote:
>
>> On Mon, 15 Dec 2008 17:48:21 -0500, mastrost <titi.mastro at free.fr>
>> 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;
}
More information about the Digitalmars-d-announce
mailing list