Closures in leu of pointers?
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sat Jun 29 15:19:12 EDT 2013
On Sat, 29 Jun 2013 12:35:54 -0600, Michael Torrie wrote:
> Python's
> basic data types are immutable. At best we could say they are read-only
> variables.
Python's basic data types are not necessarily immutable. Lists and dicts
are not immutable. Being a high-level language, the idea of "primitives"
like int, double, float, etc from C doesn't really apply. A Python dict
is not made up from Python ints. Both int and dict are equally "basic".
More importantly, you are conflating the idea of a variable (a name) and
the value of that variable (a value). Whether a variable is a named
memory location or a name binding in a namespace, it's still a name. Ints
are not names, whether they are low-level C ints or Python int objects.
Comparing the immutability of an int object (value) with the ability to
write to a name ("read-only variable" == constant) confuses the value and
the name, which is exactly what we're trying to get away from.
> So no, saying Python doesn't have variables is not the same as saying C
> doesn't have variables but only memory locations. They are different
> concepts entirely, though on the surface they look similar.
Antoon is suggesting that instead of defining:
"A variable is a named memory location, like in C"
and therefore concluding that Python doesn't have variables, we could
define:
"A variable is a name in a namespace bound to a value, like in Lisp"
and therefore conclude that Python does have variables, but C doesn't.
It's not that the two definitions are "different concepts entirely", but
that they are two subtly different forms of the same concept, a mapping
between names and values.
If they were entirely different concepts, like a list and an int, you
wouldn't have people confusing them. Nobody ever asks why Python doesn't
let you sort an int, or take the square of a list...
--
Steven
More information about the Python-list
mailing list