Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #75101

Re: Question about Pass-by-object-reference?

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Question about Pass-by-object-reference?
Date 2014-07-23 18:51 -0400
References <cc0616eb-642a-426c-a995-6665ee4c52b9@googlegroups.com> <mailman.12208.1406075253.18130.python-list@python.org> <9219a041-0d6f-4e90-b209-5fd7c50ae1fd@googlegroups.com> <mailman.12210.1406080801.18130.python-list@python.org> <53cf499c$0$29897$c3e8da3$5496439d@news.astraweb.com>
Newsgroups comp.lang.python
Message-ID <mailman.12250.1406155927.18130.python-list@python.org> (permalink)

Show all headers | View raw


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@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 
level.

>>> 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


Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Question about Pass-by-object-reference? fl <rxjwg98@gmail.com> - 2014-07-22 12:04 -0700
  Re: Question about Pass-by-object-reference? Ned Batchelder <ned@nedbatchelder.com> - 2014-07-22 15:32 -0400
    Re: Question about Pass-by-object-reference? fl <rxjwg98@gmail.com> - 2014-07-22 12:54 -0700
  Re: Question about Pass-by-object-reference? fl <rxjwg98@gmail.com> - 2014-07-22 12:34 -0700
    Re: Question about Pass-by-object-reference? Peter Pearson <ppearson@nowhere.invalid> - 2014-07-22 20:35 +0000
      Re: Question about Pass-by-object-reference? emile <emile@fenx.com> - 2014-07-22 13:46 -0700
        Re: Question about Pass-by-object-reference? fl <rxjwg98@gmail.com> - 2014-07-22 15:17 -0700
          Re: Question about Pass-by-object-reference? Joel Goldstick <joel.goldstick@gmail.com> - 2014-07-22 18:26 -0400
          Re: Question about Pass-by-object-reference? emile <emile@fenx.com> - 2014-07-22 15:33 -0700
          Re: Question about Pass-by-object-reference? Jerry Hill <malaclypse2@gmail.com> - 2014-07-22 19:06 -0400
        Re: Question about Pass-by-object-reference? fl <rxjwg98@gmail.com> - 2014-07-22 15:31 -0700
          Re: Question about Pass-by-object-reference? emile <emile@fenx.com> - 2014-07-22 15:40 -0700
      Re: Question about Pass-by-object-reference? fl <rxjwg98@gmail.com> - 2014-07-22 16:00 -0700
        Re: Question about Pass-by-object-reference? emile <emile@fenx.com> - 2014-07-22 16:10 -0700
  Re: Question about Pass-by-object-reference? Terry Reedy <tjreedy@udel.edu> - 2014-07-22 20:27 -0400
    Re: Question about Pass-by-object-reference? fl <rxjwg98@gmail.com> - 2014-07-22 18:49 -0700
      Re: Question about Pass-by-object-reference? Ben Finney <ben+python@benfinney.id.au> - 2014-07-23 11:59 +1000
        Re: Question about Pass-by-object-reference? Steven D'Aprano <steve@pearwood.info> - 2014-07-23 05:35 +0000
          Re: Question about Pass-by-object-reference? Chris Angelico <rosuav@gmail.com> - 2014-07-23 16:07 +1000
          Re: Question about Pass-by-object-reference? Ben Finney <ben+python@benfinney.id.au> - 2014-07-23 16:25 +1000
          Re: Question about Pass-by-object-reference? Terry Reedy <tjreedy@udel.edu> - 2014-07-23 18:51 -0400
            Re: Question about Pass-by-object-reference? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-24 03:22 +0000
              Re: Question about Pass-by-object-reference? Steven D'Aprano <steve@pearwood.info> - 2014-07-24 05:05 +0000
    Re: Question about Pass-by-object-reference? Steven D'Aprano <steve@pearwood.info> - 2014-07-23 05:36 +0000
      Re: Question about Pass-by-object-reference? Terry Reedy <tjreedy@udel.edu> - 2014-07-23 18:32 -0400
    Re: Question about Pass-by-object-reference? alex23 <wuwei23@gmail.com> - 2014-07-25 15:20 +1000
  Re: Question about Pass-by-object-reference? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-23 01:56 +0000

csiph-web