Re:Python becomes a platform. Thoughts on the release of clo...
by DanWaterworth on Thursday March 15, 2012 @02:34PM
(#3709869)
Python has a quite a few immutable types, tuple, string, none, boolean, int, float, but they are all primitive types. Some of Clojure's immutable types are much more interesting, like the finger tree for example.
[ Parent
| on HN ]
Re:Python becomes a platform. Thoughts on the release of clo...
by dbaupp on Thursday March 15, 2012 @11:35PM
(#3711833)
> int, float
Immutable? Could you explain this a bit more? (As far as I know, "x += 1" will modify the block of memory that x points to)
Re:Python becomes a platform. Thoughts on the release of clo...
by DanWaterworth on Friday March 16, 2012 @02:32AM
(#3712249)
No, I had to check that, but it doesn't appear to be true. `id` uses the ptr of the object in CPython, and:
>>> a = 1
>>> id(a)
32855992
>>> a += 1
>>> id(a)
32855968
So it's actually creating a new Integer object, which `a` then points to, or in other words: a += 1 is equivalent to a = a + 1
This behavior makes sense, if you wrote: a = 10
b = a
a += 20
You wouldn't expect b to be 30.