Pass by reference ?

Bjorn Pettersen bjorn at roguewave.com
Wed Apr 5 18:19:36 CEST 2000


Nick Maclaren wrote:
> 
> In article <38E8D449.FBC1E2AD at roguewave.com>,
> Bjorn Pettersen  <bjorn at roguewave.com> wrote:
> >Jacek Generowicz wrote:
> >>
> >> I'm just trying to familiarize myself with Python.
> >> In Magnus Lie Hatland's Instant Python, he
> >> mentions that `all parameters in Python are passed
> >> by reference'.
> >
> >The technically correct (although much less known) term is
> >pass-by-object-reference.  All this means is that you can change an
> >argument to a function by calling methods on the object, but you can't
> >change the identity of the object (ie. simply calling a function can't
> >change any name-bindings in your current scope).
> 
> Hang on.  Why is that technically correct?  Call by reference has
> never implied changing any bindings in the caller's scope in any
> work that I have seen - it certainly didn't back in the 1960s.
> Unless I am thoroughly confused, Python uses bog-standard call by
> reference, with the wrinkle that assignment is a rebinding rather
> than a copying operation.  AM I confused about that?

Call by reference is (at least now) generally used to refer to Pascal
VAR arguments or C++ & arguments, both of which has similar semantics
which allow rebinding in the caller's scope.  This is in contrast to
many OO languages where arguments can be mutated but not rebound...  I'm
not sure if call-by-reference has changed meaning since the 60s, but
pass/call-by-object-reference is the term consistently used when I was
doing my type theory work in 85-87...  

> The form of argument passing that DOES involve rebinding the
> caller's names certainly exists, but I have never seen an agreed
> name for it.  It was reckoned to be a bad idea (just like Fortran's
> equally deceptive argument passing of scalars) by 1970, but kept
> coming back in special-purpose languages.

Just because something is a bad idea doesn't mean you can't get a
research grant for it <wink>

--bjorn




More information about the Python-list mailing list