What other languages use the same data model as Python?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sat May 7 22:17:38 EDT 2011


On Sat, 07 May 2011 21:21:45 +1200, Gregory Ewing wrote:

> Hans Georg Schaathun wrote:
> 
>> You cannot reference nor manipulate a reference in python, and that
>> IMHO makes them more abstract.
> 
> You can manipulate them just fine by moving them from one place to
> another:
> 
>     a = b

I see no reference there, nor do I see any moving taking place. What I 
see is a name binding operation. What is happening is that the name "a" 
is being bound to the object "b" (or to be precise, to whatever object is 
currently bound to name "b").

Since you haven't explained what you think is happening, I can only 
guess. My guess is that you are thinking about some implementation of the 
Python VM which uses some sort of reference internally. Perhaps it's 
CPython, which uses pointers, or some C++ implementation which actually 
uses an indirect pointer-like data structure called "reference", or maybe 
even some old-time FORTRAN I implementation that simulates pointers with 
integer indexes into a fixed size array. It could be anything.

But whatever you're thinking of, it's not the behaviour of *Python* code, 
it's behaviour of the Python virtual machine's implementation.

It astonishes me how hard it is to distinguish between abstraction levels 
when discussing computer languages. We don't have this problem in other 
fields. Nobody talking about (say) Solitaire on a computer would say:

"Blat the pixels in the rect A,B,C,D to the rect E,F,G,H. That will free 
up the Ace of Spades and allow you to memcopy the records in the far 
right column of the tableau into the foundation."

but when it comes to high-level computer languages like Python, we do the 
equivalent *all the time*. (I include myself in this.) And people get 
into (often angry) arguments over definitions, when what they're really 
arguing about is what is happening at different abstraction levels.

A simplified view:


At the Python level: binding of objects to names. No data is copied 
except by use of a direct "copy" instruction, e.g. slicing.

At the Python VM level: objects pushed and popped from a stack.

At the VM implementation level: Name binding may be implemented by 
copying pointers, or some other reference, in some data structure 
representing name spaces. Or by any other mechanism you like, so long as 
the behaviour at the Python level is the same.

At the assembly language level: memory is copied from one address to 
another.

At the hardware level: we usually describe bit manipulation in terms of 
binary AND, XOR and OR, but even that may be an abstraction: it's 
possible that the only binary op physically used by the machine is NAND.


-- 
Steven



More information about the Python-list mailing list