Explanation of list reference
marko at pacujo.net
Sun Feb 16 12:18:51 CET 2014
Steven D'Aprano <steve+comp.lang.python at pearwood.info>:
> On Sat, 15 Feb 2014 23:01:53 +0200, Marko Rauhamaa wrote:
> I demonstrated a situation where your claim:
> id(x) == id(y) implies x is y
My from-the-hip formulation can obviously be inaccurate, but I was
hoping the point was clear.
The Python language specification feels the need to introduce the
nebulous concept of "object lifetime." I believe that concept can be
more confusing than useful. Compare that with Common Lisp, whose objects
are by definition eternal; there's no garbage collection. Practical
implementations do collect garbage, but that's an optimization that
doesn't affect the observed output of a program.
It is possible to define id() without making any references to the
Let's, then, make a more satisfactory attempt at specifying id():
1. For any argument, the function
returns an integer.
2. For any pair of arguments, the function
lambda x, y: (id(x) == id(y)) == (x is y)
That should cover all valid implementations and uses of id().
More information about the Python-list