[Python-Dev] Re: Comparison of cyclic objects
Ka-Ping Yee
ping@lfw.org
Sun, 16 Apr 2000 18:06:40 -0700 (PDT)
On Thu, 13 Apr 2000, Jeremy Hylton wrote:
> Looks like the proposed changed to PyObject_Compare matches E for your
> example. The printed representation doesn't match, but I'm not sure
> that is as important.
>
> >>> tight = [1, None, "x"]
> >>> tight[1] = tight
> >>> tight
> [1, [...], 'x']
> >>> loose = [1, [1, None, "x"], "x"]
> >>> loose[1][1] = loose
> >>> loose
> [1, [1, [...], 'x'], 'x']
> >>> tight
> [1, [...], 'x']
> >>> tight == loose
> 1
Actually, i thought about this a little more and realized that
the above *is* exactly the correct behaviour. In E, [] makes
an immutable list. To make it mutable you then have to "flex"
it. A mutable empty list is written "[] flex" (juxtaposition
means a method call).
In the above, the identities of the inner and outer lists of
"loose" are different, and so should be printed separately.
They are equal but not identical:
>>> loose == loose[1]
1
>>> loose is loose[1]
0
>>> loose is loose[1][1]
1
>>> loose.append(4)
>>> loose
[1, [1, [...], 'x'], 'x', 4]
-- ?!ng
"In the sciences, we are now uniquely privileged to sit side by side
with the giants on whose shoulders we stand."
-- Gerald Holton