passing by refference

Joshua Marshall jmarshal at madmax.mathworks.com
Wed May 14 08:14:01 EDT 2003


Fredrik Lundh <fredrik at pythonware.com> wrote:
> Joshua Marshall wrote:

>> See
>>
>>   http://wombat.doc.ic.ac.uk/foldoc/foldoc.cgi?call-by-value
>>
>> What you describe is call-by-value.

> It's interesting that you quote FOLDOC, given that FOLDOC doesn't
> refer to Python's model as call-by-value, as can be seen in the CLU
> entry:

>     http://wombat.doc.ic.ac.uk/foldoc/foldoc.cgi?CLU

>     "Arguments are passed by call-by-sharing, similar to
>     call-by-value, except that the arguments are objects
>     and can be changed only if they are mutable."

> Note the use of the words "similar" and "except".

Also interesting that

  http://wombat.doc.ic.ac.uk/foldoc/foldoc.cgi?call-by-sharing

is missing.  This is the first I've heard of call-by-sharing, but it
doesn't sound different than call-by-value to me.  (Take C for
example--pass a pointer to a struct, and you can change its fields.
This is like Python--pass a reference to a list and you can change its
elements.)

FOLDOC was just the first definition I came across when I did a
search.  For a good intro to semantics, I sugest

  Essentials of Programming Languages
  Daniel P. Friedman, Mitchell Wand, Christopher Thomas Haynes


> For a brief description of CLU's object and argument passing models,
> see [1].  I think you'll find that it matches Python's model pretty well.

> 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'm not familiar with CLU, but I think this description of Python's
argument-passing semantics is misleading.




More information about the Python-list mailing list