Partially pure (Re: Fully transitive const is not necessary)

Janice Caron caron800 at googlemail.com
Thu Apr 3 23:18:49 PDT 2008


On 04/04/2008, Walter Bright <newshound1 at digitalmars.com> wrote:
>  I think it is pure, although it might be difficult for the compiler to
> detect it. Like for CTFE, I think the compiler should start out rather
> restrictive about what it regards as pure, and over time expand it as it
> gets more capable.

What about this one. Is f pure?

    import std.date;

    void main()
    {
        invariant s = toString(getUTCtime());

        pure string f()
        {
            return s;
        }

        writefln(s);
    }

The function f relies only on the string s. which is fully invariant
and in scope. Yet f will give a different return value for the same
input (void), each time the program is run.

I assume the answer is no, but this one seems a bit grey to me. Is it
impure because s is not global?



More information about the Digitalmars-d mailing list