RE: Re: Mutable Bytes

"Mark Hahn" <[email protected]> Mon, 26 Jul 2004 23:19:03 -0700
Newsgroups gmane.comp.lang.prothon.user
Message-ID <000101c473a1$9da26110$0d01a8c0@MarkVaio>
Greg Ewing wrote:

> Mark Hahn <[email protected]>:
> 
> > I've been thinking of adding a Prothon language feature 
> that let's you 
> > set the immutable bit on any individual object.  The 
> dictionary checks 
> > that bit for allowing keys, not the object type.
> 
> That would be the wrong test for the dictionary to make.  The 
> criterion for an object being an acceptable dict key is that 
> its comparison and hash functions depend only on immutable 
> state. It can have other state that is mutable, as long as it 
> doesn't affect equality.
> 
> Python doesn't check the object type, by the way. It just 
> checks that the object has a hash function. It's up to the 
> author of the hash and cmp functions to ensure they behave 
> appropriately.

The reason I changed it to check the immutable bit is that the built-in
types aren't really immutable until they are initialized.  An Int object
will effectively change value when it goes from having no value to having a
value.  Prothon has that additional condition.

I will add the Python-like check for a hash-function.  This way any object,
even a List and Dict can be used as a key if you turn on the immutable bit.
Their hash functions will have to meet the equality test also of course.  

This will have the disadvantage that Prothon keys must be totally immutable.
Do you think this will be a problem?

Do you think I can get rid of tuples with this scheme?  Tuples are
implemented internally in Prothon as lists with the immutable bit set.
Using the new ability to set the immutable bit explicitly would give the
programmer the same capability to create a home-made tuple from any list.
I've always thought the tuple paren syntax was a kludge.