Fully transitive const is not necessary

Janice Caron caron800 at googlemail.com
Wed Apr 2 02:13:10 PDT 2008


On 02/04/2008, Bill Baxter <dnewsgroup at billbaxter.com> wrote:
> > INCORRECT. A pure function cannot read static or global data, period.
>
>  Unless the data is invariant.  Shouldn't be a problem then.

Maybe. I don't know the details. My guess would be that only manifest
constants will be allowed. Invariant data can be created with idup,
and might not be considered sufficiently pure. We shall have to wait
and see.


>  And const will not have prevented it.  So what use was its transitivity?

pure would have prevented it, and pure requires transitive const.


>  But a type that depends on globals *can* be made fully const.  So why
> doesn't that break everything?

I don't understand the question. What is a "type that depends on
globals"? Do you mean something like this:

    string g = "hello";

    class C
    {
        string s;
        this() { s = g; }
    }

I don't think that passing a const(C) to a pure function would break
anything. The essential point is not that g's character data can be
reached, it's that it can be reached /through a pointer passed to the
function/, and that's what purity requires.


> Now imagine instead of mutable int it's static int[C].  It's the same
> loophole.

It is. But again, static data will not be accessible in pure
functions, so the loophole is closed there.


> > ...or it might be screwed up entirely as a result of a threading conflict.
>
>  As would also be the case with the globals loophole.

which pure closes.



More information about the Digitalmars-d mailing list