On 5/1/2011 6:33 PM, Gregory Ewing wrote:
Steven D'Aprano wrote:
Python uses a data model of "name binding" and "call by object" (also
known as "call by sharing").
It can be summed up in a less jargony way by saying that all
data is stored in heap-allocated objects,
This is incomprehensible jargon to some; is only (partly) true of
(typical) machine-implementations; and seems not to be true of all
objects. I believe that for CPython, builtin objects, including the
fixed arrray of ints from -5 to 256, are allocated in another data
segment (more CS jargon, which is irrelavant to human interpreters).
Evidence 1:
>>> id(int)
505285072
>>> id(str)
505233232
>>> id(1)
505493792
>>> id(-5)
505493696
This appears to be initialized data segment. (Someone else could take a
white box approach and look at the source. ;-)
>>> id(333333)
16512288
>>> id('a')
11227616
This is heap.
Evidence 2:
Some error messages use 'heap type' to mean 'Python-coded class'
>>> 1 .__class__ = str
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
1 .__class__ = str
TypeError: __class__ assignment: only for heap types
http://bugs.python.org/issue4600
> and variables refer to objects rather than containing them directly.
> Everything else follows from that.
Would you say 'names refer to objects rather than containing them
directly'? Surely not. Using 'name' rather than the hugely overloaded
tern 'variable' automatically avoids certain misunderstandings.
A good summary might be "Python manipulates objects that are accessed
through literals, names, and expressions."
--
Terry Jan Reedy
--
http://mail.python.org/mailman/listinfo/python-list