passing by refference

Doug Quale quale1 at charter.net
Thu May 15 21:29:02 EDT 2003


Tim Peters <tim.one at comcast.net> writes:

> [Doug Quale]
> > ...
> > I should have let this pass in this newsgroup, but I was mildly annoyed
> > when Aahz repeatedly told Joshua that he was wrong when Joshua correctly
> > pointed out that Python is call-by-value.  Even Guido's Python Tutorial
> > correctly states that Python is cbv.
> 
> And corrected it with a footnote because, as you haven't yet picked up,
> calling Python cbv isn't *helpful*.  I'll repeat a msg from 2 years ago:
> 
>     http://mail.python.org/pipermail/python-list/2001-June/048702.html
> 
>     I usually say Python does "call by object".  Then people go "hmm,
>     what's that?".  If you say "call by XXX" instead, then the inevitable
>     outcome is a tedious demonstration that it's not what *they* mean by
>     XXX.  Instead I get to hear impassioned arguments that "by object"
>     is what any normal person means by YYY <wink>.
> 
> I'll note now that you (and Joshua, and so far) fit into the last sentence
> of that, with YYY == "call by value".  You're not the first <wink>.

(I had looked up some of your earlier posts on this issue after I
entered this morass.  Google says that "call-by-object-reference" is
most popular recently in reference to Python, often in threads that
you have participated in in this group.  The term is not unknown in
published computer science research, but it's rare.)

I'm afraid I can't determine the meaning of technical terms like
"call-by-value" by what any normal person thinks it means.  Like any
specialized technical terminology it means what expert practicioners
in the field agree it means.  This is the same in law, medicine,
mathematics, etc.  I'm sorry that so many people find this troubling,
but I don't tell a biologist that he's crazy to say that the giant
panda is more closely related to the racoon family than the bear
family just because it's my hobbyist opinion that it's obvious that a
panda is a bear.  (I read recently that there is more evidence that
the giant panda is more closely related to the bear than the racoon,
but apparently the issue still isn't settled definitively.)

>     BTW, I believe Barbara Liskov first coined "call by object" to
>     describe argument-passing in CLU.
> 
> A primary difference between you and Joshua and responders (including me,
> Aahz, Jeremy, Fredrik and Terry), is that we've been explaining Python to
> newcomers for many years.  The idea that "call by value" has One True
> Objective Meaning is simply silly, as actually doing the literature search I
> suggested at the start would have shown you.  It's used to mean several
> distinct things, depending on the programming culture using it.  Even so, in
> no case does it have enough explanatory power to answer most practical
> questions about the semantics of calls in Python.

What practical question can it not explain about calls in Python?  It
very easily explains the example you gave before.

>  Therefore it's useless as
> a pedagogical device here.  In contrast, Liskov's description of "call by
> object reference" explains just about everything, and applies almost
> verbatim to CLU, Smalltalk, Python, and-- with a little bit of squinting to
> exempt special forms and macro calls --a majority of Lisp variants.

Argument passing in Java and C are no different from Python.  The same
mutation that you showed in your Python example occurs there too.  Do
you think that "call by object reference" explains them?  Java and C
are both usually considered to be call-by-value, but you seem to have
a different opinion.

> So I don't care what you (or Joshua) want to insist "call by value" means --
> no matter what it means to you, it doesn't *help* here.  If you care to
> learn something new, I recommend Henry Baker's "Equal Rights for Functional
> Objects", which argues the issue in detail in the context of Lisp:
> 
>     http://home.pipeline.com/~hbaker1/ObjectIdentity.html
> 
> I'll just quote the start of section 7 ("Call-by-reference versus
> call-by-value") here:
> 
>     Despite the thirty years that the problem of "call-by-reference"
>     versus "call-by-value" in argument-passing semantics of Algol-like
>     programming languages has been discussed, it has never been clearly
>     resolved.  While many undergraduate texts [Aho86,s.7.5] and language
>     manuals give a definition of each policy, there has always been a
>     nagging feeling that these definitions for Algol-60, Fortran and Ada
>     are too ad hoc and too implementation-oriented.
> 
>     ...
> 
>     We claim that the only argument-passing model that is consistent
>     in non-functional languages is call-by-object-reference, i.e.,
>     passing object identities.

> 
> He goes on to explain why it's incorrect to call Lisp "call-by-value", and I
> agree -- provided that by "call-by-value", you mean the One True Objective
> Meaning it had when I was your age <wink -- I'm afraid it had several
> meanings then too, and that's only gotten worse, the most recent abuse being
> the widespread adoption (in one sub-culture) of using cbv to mean
> applicative-order evaluation>.

Henry Baker is a very bright guy, but I'm not on the bus with this one.
I didn't just invent a definition for call-by-value based on what I
thought it should mean.  I learned the definition at school from
professor Fischer.  Professor Fischer researches computer programming
languages, and I presume that he taught his class the definition of
the term as it is used in the field.

Here is what Ravi Sethi says in "Programming Languages: Concepts and
Constructs":

"The effect of a procedure call in a programming language depends on
the answer to the following question:

    What is the correspondence between the actual parameters in a
    procedure call and the formal parameters in the procedure body?

The answers examined in this section are motivated by differing
interpretations of what a parameter stands for.  Does an actual
parameter A[j] in a procedure call P(A[j]) represent its r-value, its
l-value, or the program text A[j] itself?  Some interpretations are

   * Call-by-value.  Pass the r-value of A[j].
   * Call-by-reference.  Pass the l-value of A[j].
   * Call-by-name.  Pass the text of A[j] itself, avoiding "name clashes."

Another variant, examined later, is call-by-value-result."

If Python is not call-by-value, what is an r-value in Python that
differs from what is passed to a function?  Basically I want you to
explain why Python is not call-by-value by this definition (and the
one used in Aho, Sethi and Ullman which not surprisingly is the same).
If Python is not cbv by this definition then it is clearly not cbv.
In that case, I was wrong, the debate is over.  If Python is cbv by
this definition then it's clear that you don't accept this definition.
That's fine, but then it would be helpful to know what your definition
of call-by-value is.

> If thinking of Python as being cbv helps you to understand it, I certainly
> don't object to that.  The evidence of the last decade is that it actively
> hinders understanding for most newcomers, but that explaining call-by-object
> actively helps.

I have no objection to calling Python argument passing
call-by-object-reference.  (I would be curious to know why you think
that is different from call-by-value in a language like Python where
r-values are object references.)  On the other hand, if someone says
Python argument passing is call-by-value I don't recommend telling him
he's wrong as Aahz did what seems like thousands of messages ago.

> stick-around-and-you'll-eventually-agree-ly y'rs  - tim

I have to say that your posts always make me smile.  comp.lang.python
is a remarkably friendly forum and I apologize to all for a cranky
post or two I made earlier.




More information about the Python-list mailing list