pure or not pure?
Georg Wrede
georg at nospam.org
Thu Apr 10 11:04:02 PDT 2008
Leandro Lucarella wrote:
> Steven Schveighoffer, el 10 de abril a las 10:42 me escribiste:
>
>>So let me restate: not having the ability to pass around UNIQUE mutable heap
>>data to and from pure functions is going to limit severely the usefulness of
>>pure functions.
>
>
> This is the exact same problem of the mutable methods of a class used in a
> stack allocated temporary of a pure function, talked in another thread.
>
> class A {
> int x;
> void f() { x = 1; }
> }
>
> pure void g()
> {
> scope a = new A;
> a.f();
> }
>
> g() is clearly pure (it has no side effects, besides allocating memory in
> the stack, which shouldn't be considered a side effect, I guess allocating
> in the heap shouldn't be considered a side effect either, since new is
> thread safe). Even when A.f() is not pure, nor const.
>
> There is an implementation problem, about how hard is to detect that by
> the compiler, but in theory there is no reason for g() not being pure.
g doesn't return a value.
More information about the Digitalmars-d
mailing list