PEP 218 Re: ANN: set-0.1 module available

Huaiyu Zhu huaiyu at gauss.almadan.ibm.com
Mon May 20 13:51:00 EDT 2002


Erik Max Francis <max at alcyone.com> wrote:
>That's not the half of it.  Mutable objects can dynamically change
>state, completely outside the control of the container.  So the hard
>question is:  What happens when a mutable object changes its value, such
>that it effects the arrangement of the set?  How does the container get
>notified of this change (which as far as I know there is no standard way
>to test in Python), and what happens when a value collision occurs
>within the set?  Does one object get disposed?  If so, which one?

Conclusion: Mutable objects cannot be consistently hashed by contents.

There is no escape the fact that mutable and immutable objects are
fundamentally different.  Mathematically a mutable set is a sequence of sets
indexed by time.

The solution appears to be:
- Allow mutable and immutable flavors of objects.
- Mutable objects are hashed by identity.
- Immutable objectas are hashed by content.

No change would then hanve the undesirable effect you described.

Huaiyu



More information about the Python-list mailing list