Extended Type Design.

Bill Baxter dnewsgroup at billbaxter.com
Fri Mar 16 19:44:08 PDT 2007


kris wrote:
> Andrei Alexandrescu (See Website For Email) wrote:
>> kris wrote:
> [snip]
>>> So, "invariant" is already a keyword ... what about that?
>>>
>>> "Invariant" is currently used to stipulate a condition that must 
>>> remain constant (or true) for the extent of the enclosing/relevant 
>>> scope. Right now, it is used within a class only, but the semantics 
>>> could presumably extend elsewhere too:
>>>
>>> invariant int * p = &x;
>>>
>>> void myFunc (invariant char[] arg) {}
>>>
>>> in both these cases, the "invariance" should remain for the extent of 
>>> the relevant scope?
>>
>>
>> I completely missed that one. I think it's a good idea to look into it 
>> as a candidate for a qualifier name. Thank you.

Typically with invariants in CS the meaning is that "you can change all 
you want as long as you put things back the way you found them when 
you're done".  And that's definitely not the connotation desired here.

> If it gets tossed for whatever reason, It might be worthwhile renaming 
> the current "invariant" to whatever is settled upon? That may reclaim a 
> keyword at least.

Invariant can refer to an abstract property that doesn't change, like 
"full.length + empty.length == buffer.length".  The individual 
constituents of that expression can change all they want.  So calling it 
constant/readonly/immutable doesn't make as much sense as 'invariant'.

--bb



More information about the Digitalmars-d mailing list