anything like C++ references?

Tom Plunket tomas at fancy.org
Tue Jul 15 01:15:08 CEST 2003


Stephen Horne wrote:

> All you have proven is that it is the distinction between types 
> that get re-bound and those that don't (rather than the use of 
> references) that is unnecessarily confusing and error prone.

As the firestarter (I apologize for the flames that have
erupted), I must admit that even I know that this distinction
does not exist in Python.  There aren't some types that get
rebound and others that don't.

def fn(arg):
   local = SOME_GLOBAL
   local = arg

local gets rebound to arg regardless of what the types involved
are, period.

> The wart remains, even if my description was wrong. And even that 
> is a dubious claim.

I still feel that there's a wart of some sort, but it's not due
to any inconsistency in the language, despite what I may have
said before (I've been thinking about it a lot over the past few
days).

> A Python user is interested in how an object behaves - not how it 
> is internally implemented in the interpreter. Immutable objects 
> don't behave as references - the internal use of references for 
> immutable objects is basically a lazy copying optimisation and, 
> apart from performace and a couple of other technicalities (e.g. 
> the 'is' operator), has no relevance.

Are they really technicalities, though?  I mean, a mutable object
can be changed.  It's the same object, just changed.  Immutable
objects, however, can't be changed.  You can get something that
appears like changing it, but it's actually building a new thing
and binding the label to that new thing.

What I specifically want is a way to have a "second-level
binding", e.g. a reference to a reference (assuming that the
terminology is correct by saying that all Python variables are
references).  This is where I see the hole in Python, that there
actually is a class of object that is different from everything
else; you can bind to anything at all in the language...except
references.

-tom!




More information about the Python-list mailing list