Question about Pass-by-object-reference?
tjreedy at udel.edu
Thu Jul 24 00:51:47 CEST 2014
On 7/23/2014 1:35 AM, Steven D'Aprano wrote:
> On Wed, 23 Jul 2014 11:59:45 +1000, Ben Finney wrote:
>> fl <rxjwg98 at gmail.com> writes:
>>> On Tuesday, July 22, 2014 8:27:15 PM UTC-4, Terry Reedy wrote:
>>>> When you call a function, Python binds function parameter names to
>>>> argument objects in the function's local namespace, the same as in
>>>> name assignments. […]
>>>> Nothing is being 'passed'.
Non-human implementations copy object ids, but I was not writing at that
>>> Thanks, but I don't understand your point yet. Could you give me
>>> another example in which something is passed?
>> The point being made is that no values are is “passed” in a function
>> call. If you have learned that term from elsewhere, it doesn't apply
>> sensibly to Python.
> Hmmm. I don't know that I like that. I think that these two sentences
> mean the same thing:
> "Call the function with x as argument."
> "Pass x to the function."
I disagree. In Python, when one calls the function with an argument,
computer implementatipns 'pass' an object reference, which in CPython is
an object address. Conflating the two sentences above leads people to
claim that python 'calls by (object) reference'. In a sense, it does,
But thinking in those terms often leads to false inferences about how
Python behaves. So I think it better not to think is such terms.
> They both describe what is being done, only from slightly different
> points of view.
'Passing' is an implementation of calling. I have little idea what *I*
do when interpreting a function call while interpreting python code.
> In mathematics, to call a function is a completely
> abstract action. Magic happens, and a result is returned.
From a set theory point of view, nothing happens. The result simply is
the second member of the pair with the argument as the first member.
> But in programming languages, calling a function has concrete actions:
The *essential* concrete action is the binding of something to parameter
names. 'Passing' is a means to that end. What matters is what gets
bound. In Python, python objects themselves get bound. And the binding
is essentially the same as in assignment statements. Other language bind
values or references or pointers or ..., with different consequences.
Terry Jan Reedy
More information about the Python-list