Extended Type Design.

Derek Parnell derek at nomail.afraid.org
Tue Mar 20 18:06:51 PDT 2007


On Tue, 20 Mar 2007 17:24:49 -0700, Andrei Alexandrescu (See Website For
Email) wrote:

> Derek Parnell wrote:
>> On Tue, 20 Mar 2007 16:01:35 -0700, Walter Bright wrote:
>> 
>>> A symbol is a name to which is 'bound' a value.
>>  ...
>> 
>>> Here, we bind a new value to the symbol x:
>>>      x = 4;
>> 
>> I used to use the verb 'to assign' for this concept. I guess that's still
>> okay or must I modernize <G>
> 
> You may want to modernize. "Assign" doesn't quite catch the notion of 
> indirect reference, 

Okay, if you say so, but I'm not having an issue with the concept of
assigning value to something directly or indirectly.

> and from a couple of posts I understand that this is 
> a source of confusion.

Not for me, but thanks anyway.

> A very useful way to see "int x = 4;" is that the symbol x is bound to 
> the Platonic number 4. The 4 itself cannot change. You can rebind x by, 
> say, writing ++x. That unbinds x from Plato 4 and binds it to Plato 5. 

Huh? Just looks like a fancy way of saying 'x' first gets assigned the
value 4 then later, using ++x, gets assigned the value 5. By whatever, I'll
not get hung up as I think we are on the same track here.

> Once this is clear, the notions of values and references clarifies a lot.

It does? How? If pressed, I'd say that the only difference between 'assign'
and 'bind' is that 'assign' maybe implies an 'assignment statement' was
used to change the value, but 'bind' doesn't care how the change is caused.

>>> static int x = 3;
>>>
>>> '3' is the value.
>>> 'int' is the type.
>>> 'x' is the symbol.
>>> 'static' is the storage class.
>>>
>>>
>>> A storage class originally meant where the symbol is stored, such as in 
>>> the data segment, on the stack, in a register, or in ROM. It's been 
>>> generalized a bit since then. The main way to tell a storage class apart 
>>> is that:
>>> 1) a storage class applies to the symbol
>> 
>> "to the symbol"?  Don't you mean "to the data that the symbol represents"?
>> In the case above, the symbol is 'x', and I don't think 'x' is being stored
>> anywhere except in the compiler's internal tables, and I'm sure 'static'
>> isn't referring to the compiler's internals.
> 
> The meaning was simple. When you say "poor fella Jim", "poor" applies to 
> Jim, not to "fella".

Oh, okay ... its not a 'static int' (a type) but a 'static x' (a value
represented by the symbol 'x').
 
>>> 'invariant' is a guarantee that any data of that type will never change. 
>> 
>>  class Foo 
>>  { 
>>    int a; 
>>    char[] s; 
>>    this(char[] d)
>>    {
>>        s = d.dup;
>>        a = s.length;
>>    }
>>  }
>>  invariant Foo f = new Foo("nice");
>> 
>>  f.a = 1; // fails??? changing f's data
>>  f.s = "bad"; // fails??? changing f's data
>>  f.s.length = 1; // fails??? changing f's data
>>  f.s[0] = 'r'; // okay ??? not changing f's data
> 
> They all fail. The last fails because invariance is transitive. All that 
> could be done is to rebind f to another invariant object.

Thanks. I'm just trying to get all this straight in my mind. So the
definition should be more along the lines of ...

'invariant' is a guarantee that any data accessible from that type will
never change. 

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Justice for David Hicks!"
21/03/2007 11:52:49 AM



More information about the Digitalmars-d mailing list