"always passes by reference"

Greg Weeks weeks at golden.dtc.hp.com
Tue Jul 25 20:54:59 EDT 2000


Once upon a time, "pass by reference" meant that a function call f(x) could
modify the binding of the variable x.  With this definition, "pass by
reference" effectively passes the address of the variable x to the
function.  "pass by value", by contrast, passes only the value of the
variable x, not its address.

With these definitions, Python is uniformly "pass by value".  So are Lisp,
Java, and C, but not C++ and Perl.

I like these old definitions.  Unfortunately, things now get confusing when
the value of a variable is an address.  This wasn't always the case.  In
the Lisp and Smalltalk communities back in the early 80's (as I recall), it
was generally understood that an interesting mutable data type (such as a
list) is implemented internally as an address.  The address isn't a
"reference" to a list.  The address IS the list.  But now it seems that
under the influence of C and especially C++, the notion that an address can
represent a thing (such as a list) is entirely out of favor.  Oh, well.

I prefer the old way of speaking.  With the new way of speaking, both
Python and Perl are "pass by reference", but Perl is somehow *more* so.
That's confusing.  And in the new way of speaking, in Python you don't pass
numbers, lists, and so on to functions.  You have to say that you pass
"references" to these things.  But when you're in a hurry, you skip this
"references" business and talk about passing numbers, lists, and so on.
This hasty way of speaking used to be considered correct, and I still like
it.

Regards,
Greg



More information about the Python-list mailing list