On 2/23/2014 6:01 AM, Marko Rauhamaa wrote:
As for Python, there's nothing in the Python specification that would prevent you from having, say, 63-bit integers as representing themselves. IOW, you could physically place such integers as themselves as the reference and the number would not physically exist elsewhere.
The Python spec requires that ints act as if they are independent objects with about 20 attributes and methods. The language spec is based on duck typing everything as an object with a class and attributes.
Revised code would have to either turn the reference int into a real object on every access (which would be tremendously inefficient), or code special case treatment of reference ints into *every* piece code that might act on ints (which is all over the interpreter) so as to simulate the int object behavior. id(someint) is the least of the problems.
Special-casing ints to store the value in the reference has been proposed and rejected. I do not remember how far anyone went in trying to code the idea, but I doubt that anyone got as far as getting the test suite to pass.
Bottom line, there's no fundamental difference between C and Python variables.
Hogwash. Int variables are not all variables. And as I explained above, even if one stored Python ints much like C ints, one would have to add code to hide the fact that one had done so.
-- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list