What other languages use the same data model as Python?

Hans Georg Schaathun hg at schaathun.net
Tue May 3 16:47:04 EDT 2011


On Tue, 03 May 2011 12:33:15 -0400, Mel
  <mwilson at the-wire.com> wrote:
:  mwilson at tecumseth:~$ python
:  Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) 
:  [GCC 4.4.3] on linux2
:  Type "help", "copyright", "credits" or "license" for more information.
: >>> def identify_call (a_list):
:  ...   a_list[0] = "If you can see this, you don't have call-by-value"
:  ...   a_list = ["If you can see this, you have call-by-reference"]
:  ... 
: >>> my_list = [None]
: >>> identify_call (my_list)
: >>> my_list
:  ["If you can see this, you don't have call-by-value"]

This looks like plain old transmission by reference to me.
I.e. the functions get a reference to an object and make any
change to the object.  Since the caller and the callee refer 
to the same object, changes made by the callee are seen by
the caller.  However, the reference cannot be changed.

With transmission by name, you would get what you call
call-by-reference; i.e. the variable passed as an argument is
changed to refer to a completely new object.  In simula this 
is used for output parameters.

And transmission by value is of course a copy of the data.

:  so it's neither call-by-value nor call-by-reference as (e.g.) C or PL/I 

I don't know PL/I; that's the sort of thing my mother deals with.
Simula explicitely offerts all three.  In C you can get each of the 
three, by using pointers explicitely in different ways.

Whether you use C or Simula, transmission by reference, that is what
python appears to be doing, seems to be the normal approach for any
composite data type.  Thus python does not seem to do anything out of
the ordinary at all.

-- 
:-- Hans Georg



More information about the Python-list mailing list