Fully transitive const is not necessary

Walter Bright newshound1 at digitalmars.com
Wed Apr 2 17:59:00 PDT 2008


Jason House wrote:
> Walter Bright wrote:
> 
>> If you do away with transitive const, you cannot have invariant either.
>> Const allows you to reuse code that works on invariants to work with
>> mutables, too.
>>
>> Logical const just utterly breaks the whole system. Every scheme we've
>> looked at for logical const winds up in some way breaking invariants. If
>> invariants are broken, the advantages of them all just go away. I
>> suspect that logical const is like perpetual motion - if you think
>> you've solved it, you've just made a mistake somewhere <g>. I also
>> suspect that the failure of logical const validates the D scheme of
>> invariants as being correct - there shouldn't be any holes in it.
>>
>> You're right that invariant by itself is not enough to specify a pure
>> function, a pure function also cannot read or write global state. But
>> invariant is still a necessary condition, it's just not sufficient.
> 
> Is it possible to describe what tricks the compiler can do given:
>  A. transitive const      w/ mutable access to globals/statics
>  B. transitive invariance w/ mutable access to globals/statics
>  C. transitive const      w/ const access to globals/statics
>  D. transitive invariance w/ invariant access to globals/statics
> 
> It'd be extremely helpful to have that kind of discussion in the const FAQ. 
> Without it, I feel like we're all discussing theoretical stuff with little
> basis for our arguments.

Sure, but static class members are *not* part of the transitive closure 
state of the object. They're just global variables.

> PS: I went to digitalmars and couldn't find the const FAQ.  It's not linked
> to from the normal FAQ and is not included in the left-side bar on the D
> 2.0 page(s).

That'll happen with the next update.



More information about the Digitalmars-d mailing list