On Thu, 08 May 2014 18:14:48 +1000, Chris Angelico wrote: > On Thu, May 8, 2014 at 6:07 PM, Joseph Martinot-Lagarde > <joseph.martinot-laga...@m4x.org> wrote: >> For me, names bound to values is the same concept as pointer pointing >> to memory. bar = foo copies the pointer and not the underlying memory. >> This is not a foreign concept to C programmers. >> >> > That is how it's implemented in CPython, after all... modulo the whole > refcounting thing, of course. But that's not strictly a part of the > definition of Python; it's just implementation.
Yes. And that's *not* how Jython or IronPython implement it, since neither Java nor .Net provide pointers (in the C sense). Nor does PyPy, which is Python written in Python (to be pedantic, RPython). Now obviously you need to have *some* way to implement indirect references. If this were 1965 or so and we were implementing Python in FORTRAN, we'd use a big array and use array indexes as our "pointers". After all, isn't that what C pointers are like? The index (address) of a block of memory in a giant array (the heap)? Given the architecture of our computing devices, I would expect that if you go down deep enough, you would find something like a C pointer. But Python is not necessarily implemented on such a device. In principle, we could write a Python interpreter on a Turing machine, or using clockwork. "Python uses pointers" is an *implementation detail*, not a language feature. > You could implement > Python on pencil-and-paper (aka a dry run), and as long as you have a > concept of names that reference objects, it's going to be fine. The > "reference" might be done with a physical piece of string connecting a > Post-It note with a name to a box with the object's state, meaning > there's no way of copying any pointer, and it's still Python. Yes, exactly. -- Steven D'Aprano http://import-that.dreamwidth.org/ -- https://mail.python.org/mailman/listinfo/python-list