"always passes by reference"

Donn Cave donn at u.washington.edu
Thu Jul 27 20:06:27 EDT 2000


Quoth weeks at golden.dtc.hp.com ((Greg Weeks)):
...
| Also, the function call f(x) is by-value.  The function receives the object
| that has been written into the variable x.  If the object is mutable -- ie,
| if there is some way to modify the region of storage addressed by the
| object -- then the function may change the *state* of the object.  But the
| function can not write a different object into the variable x.
|
| So, the distinction between "objects" and "references to objects" is not
| *necessary*.  Whether or not it is *desirable* is to some degree a matter
| of taste.

Your account of the system doesn't work for me.

    def f(x, t):
        x = t

Where is the "the variable x"?  Did f() just write a different object
into it?  Well, in any practical sense, x does have a new value.

Except, if t was actually the same value as x.  Now this leads to the
question, does that mean equivalent object?  Or it could be the same
object!

How can x and t both refer to the same object, at the same storage
location if you like, without making a distinction between objects
and references to objects?  How can x acquire the value of t, without
overwriting the object that was its previous value?

Mutability is not an issue here.  No object is mutable in the sense
of changing its identity in any way.  When we use this term, we're
really talking about containers and limits to their contents.  A few
allow contents to be added or subtracted, but that makes no difference
in how they are treated as objects.

A Python program is a system.  Objects are nodes in that system,
things with properties.  References are the connections that define
their existence within the system.  Neither is meaningful without
the other, but in no way are they the same.

I have also seen the term "binding" used (as a noun) in what looks
like a similar context.  Sounds like a lot more work though, binding
and unbinding things all the time, when a person could simply refer
to them.

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list