[Python-Dev] redefining is
Jewett, Jim J
jim.jewett at eds.com
Thu Mar 18 10:23:07 EST 2004
Andrew Koenig:
> The observation is that if an object is immutable, there's
> no legitimate reason to know whether it's distinct from
> another object with the same type and value.
There is an idiom (I've seen it more in Lisp than in python)
of creating a fresh object to act as a sentinel.
"done with this data" might well appear in the input, but
the specific newly-created-string (which happens to look
just like that) can't appear.
The sentinal is usually a mutable object, but it is sometimes
a string indicating the object's meaning. ("fail") It is
surprising that some objects (like small integers) cannot be
used, but I don't think the answer is to make the entire
idiom unusable.
You could argue that they ought to be using (id(x) == id(y))
to emphasize that == isn't enough, but ... (x is y) seems
just as clear, and the reference manual (5.9) says that is
tests for object identity.
-jJ
More information about the Python-Dev
mailing list