passing by refference

Tim Peters tim.one at comcast.net
Thu May 15 19:13:12 EDT 2003


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

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

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

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.

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






More information about the Python-list mailing list