Finding the instance reference of an object

Douglas Alan doug at alum.mit.edu
Thu Oct 30 23:14:22 EDT 2008


greg <greg at cosc.canterbury.ac.nz> writes:

> Douglas Alan wrote:
>> greg <greg at cosc.canterbury.ac.nz> writes:
>>
>>>Seems to me that (1) describes exactly how parameter passing
>>>works in Python. So why insist that it's *not* call by value?
>> Because there's an important distinction to be made,
>
> The distinction isn't about parameter passing, though, it's about
> the semantics of *assignment*. Once you understand how assigment
> works in Python, all you need to know then is that parameters are
> passed by assigning the actual parameter to the formal
> parameter. All else follows from that.
>
> This holds for *all* languages that I know about, both
> static and dynamic.

Then you don't know about all that many languages.  There are
languages that use call-by-name, and those that use
call-by-value-return.  Some use call-by-need and others do
call-by-macro-expansion.  Etc.  These languages generally don't use
these same semantics for assignment.

All languages that I know of that use call-by-sharing also do
assignment-by-sharing.  Not all languages that do
assignment-by-sharing always do only call-by-sharing, however.  For
instance, most dialects of Lisp have procedural macros.  The calling
semantics of procedural macros are quite different from the calling
semantics of normal functions, even though procedural macros are Lisp
functions.  Other dialects of Lisp provide the ability to state that
certain function arguments won't be evaluated at call time.  All
dialects of Lisp, however, do assignment-by-sharing, or "binding" as
it is called in the Lisp community.

Also, one could certainly invent additional languages that do behave
in the typical manners.

If you are merely asserting, however, that understanding how Python
does assignment will help you understand how Python does argument
passing, then you are certainly correct.  This, however, does not
imply that there is not a pre-existing precise terminology to describe
Python's calling semantics, and that this term can be useful in
describing how Python works.

If I tell you, for instance, that Java, Python, Ruby, JavaScript,
Lisp, and CLU all use call-by-sharing, then I have said something that
makes a similarity among these languages easier to state and easier to
grasp.

> Once you know how assignment works in the language concerned, then
> you know how parameter passing works as well. There is no need for
> new terms.

This is simply not true.

>> and the distinction has been written up in the Computer Science
>> literature since Lisp first starting using the same argument
>> passing semantics as Python back in 1958.  The semantics are called
>> "call by sharing".
>
> I still think it's an unnecessary term, resulting from confusion on
> the part of the authors about the meanings of the existing terms.

Trust me, Barbara Liskov was not one bit confused when she invented
the term "call-by-sharing". And her language CLU was one of the most
prescient to have ever been designed and implmented.

> If there's any need for a new term, it would be "assignment by
> sharing". Although there's already a term in use for that, too --
> it's known as reference assignment.

Reference assignement doesn't imply that the object is allocated on a
heap, and "call-by-sharing" does.

>> Many mainstream programming languages other than Python now use call
>> by sharing.  They include Java, JavaScript, Ruby, ActionScript, and C#.
>
> I would say they use assignment by sharing, and call by value.

We can also argue about how many angels can dance on the head of a
pin, but the term "call-by-sharing" has been around since the 70s, and
it is already well-defined and well understood.

|>oug



More information about the Python-list mailing list