Explanation of list reference
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sat Feb 15 21:27:41 EST 2014
On Sat, 15 Feb 2014 15:40:54 -0500, Terry Reedy wrote:
> 'Identity' is an abstraction. For immutable objects, it is essentially
> irrelevant. For mutable objects, it is essential in the following sense.
> A and B are the same object if mutating A necessarily mutates B and
> different if they can be independently mutated.
That's not quite right. See the earlier example in this thread about
numpy arrays. Since mutator methods can have side-effects, and objects
can act as proxies or views to other methods, we can't make any
conclusion about identity from the fact that mutation affects two or more
objects.
[Aside: I think the numpy array API is poor, since it doesn't make clear
the distinction between arrays which are being used as views to another
array, and arrays which are being used as independent arrays.]
--
Steven
More information about the Python-list
mailing list