Pass by reference ?
Nick Maclaren
nmm1 at cus.cam.ac.uk
Mon Apr 3 14:39:53 EDT 2000
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?
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.
Regards,
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QG, England.
Email: nmm1 at cam.ac.uk
Tel.: +44 1223 334761 Fax: +44 1223 334679
More information about the Python-list
mailing list