4 ms·
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
by DanWaterworth 15y ago
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.
- dbaupp 15y ago> 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)
- DanWaterworth 15y agoNo, 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.