[Python-Dev] redefining is (original) (raw)
Michael Chermside mcherm at mcherm.com
Fri Mar 19 12:59:00 EST 2004
- Previous message: [Python-Dev] redefining is
- Next message: [Python-Dev] redefining is
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Andrew Koenig writes:
The reason for that, I think, is that there are really three kinds of "equality" that make sense, and only two of them are reasonably available:
Value equality (==, which might be user-defined, because the concept of "value" can be user-defined); Object identity ("is") Object equivalence (no easy way of expressing it today) By "object equivalence", I mean mutual substitutability--which is the same as identity for mutable objects, but not for immutable ones.
You'll have to help me out here... I just don't get it.
Starting from your definition of object equivalence, let us divide all objects into two clases: mutable and immutable. Actually, instead I'm going to follow Martin v. Löwis' example[1] and divide all objects into identitiy objects, mutable values, and immutable values.
Considering the meaningful concepts for each category:
Identity Objects can be (meaningfully) compared by:
* Object Identity
To see if these are "the same object". Also useful
for low-level memory stuff according to Tim.
(just use '==', although 'is' would work too)
Mutable Values can be (meaningfully) compared by:
* Value Equality
To see if these represent the same value.
(just use '==')
* Object Identity
Whether two references will STAY equal if one is changed.
Same as "mutual substitutibility" or "object equivalence".
According to Tim, this is also handy for low-level memory
stuff.
(just use 'is')
Immutable Values can be (meaningfully) compared by:
* Value Equality
To see if these represent the same value. Same as
"mutual substitutibility" or "object equivalence".
(just use '==')
* Object Identity
Whether two objects are actually using the same memory
location. Useful ONLY for low-level memory stuff a la Tim.
(just use 'is')
Seems to me as if there are no more than TWO meanings for any given type of object, and that we provide two comparison operators in each case. So what's missing?
-- Michael Chermside
[1] http://mail.python.org/pipermail/python-dev/2004-February/042579.html
- Previous message: [Python-Dev] redefining is
- Next message: [Python-Dev] redefining is
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]