passing by refference

Doug Quale quale1 at charter.net
Thu May 15 17:25:48 EDT 2003


"Fredrik Lundh" <fredrik at pythonware.com> writes:

> The CLU Reference Manual [2] by Liskov et al says (page 14):
> 
>     "We call the argument passing technique _call by sharing_,
>     because the argument objects are shared between the
>     caller and the called routine.  This technique does not
>     correspond to most traditional argument passing techniques
>     (it is similar to argument passing in LISP).  In particular it
>     is not call by value because mutations of arguments per-
>     formed by the called routine will be visible to the caller.
>     And it is not call by reference because access is not given
>     to the variables of the caller, but merely to certain objects."
> 
> Note the use of "does not" and the repeated use of "it is not".
> Let me emphasise:
> 
>     "IN PARTICULAR IT IS NOT CALL BY VALUE because mutations
>     of arguments performed by the called routine will be visible to
>     the caller. And IT IS NOT CALL BY REFERENCE because access
>     is not given to the variables of the caller, but merely to certain
>     objects."

I don't know CLU but I suspect that CLU was/is call-by-value.  The
statement about mutations of arguments and cbv is striking -- it's
just plain wrong.  This is a remarkably powerful misconception.
C array arguments can be mutated and yet C is pure call-by-value.

Barbara Liskov is a smart person and an important programming language
researcher (one of the early pioneers of OOP), but saying that CLU is
similar to Lisp and yet claiming CLU is not cbv is a contradiction.
This is just an error.

The terms "call-by-sharing" and "call-by-object-reference" are fine,
but they aren't particularly popular in the programming language
research community.  I suspect this is because they don't really say
anything -- they both describe call-by-value.

If you say that Python is call-by-object-reference, then you would
also have to say that Python is assignment (or binding) by object
reference, because the value of x inside f() in

def f(x):
    x[:] = [-1] * 3

y = [1, 2, 3]
f(y)

is exactly the same as if x were bound directly, as in

y = [1, 2, 3]
x = y
x[:] = [-1] * 3

That's OK, but it's much simpler and saner to just say that Python
binding and function calls work the same way.  In both cases the
r-values are object references.  When looking at the Python statement

x = y

I say that x is bound to the value of y (and the value of y is a
reference to some object), not x is bound to a reference to the value
of y.  If you choose to say "reference to the value of y" then values
will never appear in any description of Python -- everything will be
references to values.  This is silly.  The values are object
references, and everything follows smoothly.

Using a name different from cbv is necessary when function parameters
are bound differently than they are by an assignment statement.  This
happens in Fortran (call-by-reference), Algol (call-by-name), etc.  It
doesn't appear to happen with call-by-sharing or call-by-value.




More information about the Python-list mailing list