4 ms·
Speaking as someone who Friday had to fix an embarrassing bug in my Python code because lists aren’t immutable when passed to another function, I like the way y
by macintux 5y ago
Speaking as someone who Friday had to fix an embarrassing bug in my Python code because lists aren’t immutable when passed to another function, I like the way you think.
I will say, however, that what I want from Python isn’t actually “frozen” data structures but cloned ones (or, like some/most FP languages, structures with nested values that are only cloned when necessary).
Vals, not vars.
- BerislavLopac 5y ago> lists aren’t immutable when passed to another function Well, lists are never immutable in Python; you want to use tuples for that.
- macintux 5y agoTrue, what I really want is referential transparency, not immutability per se. I’ve only used tuples in Python as a small data structure, will have to experiment with using them as a list substitute, thanks.
- BerislavLopac 5y agoJust keep in mind that a tuple's elements can still be mutable, so it's not a "frozen" data structure throughout.
- diegojromero 5y agoInteresting idea, instead of a deep clone, would it be something similar to the copy-on-modify pattern?
- macintux 5y agoCopy on modify would work, certainly. The term I was forgetting when I wrote that is “persistent” data structures, but I’m not sure whether it’s practical to implement persistent structures in a non-functional language like Python. https://hypirion.com/musings/understanding-persistent-vector-pt-1 https://hypirion.com/musings/understanding-persistent-vector...