7 ms·
I like the idea of immutable-by-default, and in my own musings on this I've imagined a similar thing except that instead of a mutable keyword you'd have somethi
by sunrunner 11mo ago
I like the idea of immutable-by-default, and in my own musings on this I've imagined a similar thing except that instead of a mutable keyword you'd have something more akin to Python's with blocks, something like:
# Immutable by default
x = 2
items = [1,2,3]
with mutable(x, items):
x = 3
items.append(4)
# And now back to being immutable, these would error
x = 5
items.append(6)
I have put almost zero thought into the practicality of this for implementation, the ergonomics for developers, and whether it would be different enough and useful enough to be worth having.
- pizza234 11mo agoThis is in essence a mutable borrow - by looking at Rust's borrow checker, one can see the complexities of the concept.
- danenania 11mo agoClojure has transients—a similar idea I believe. Basically bounded mutation.
- unrealhoang 11mo agoWithout a borrowck, inside your mutable block, another variable can reference to the mutable version of your x or items, and be mutated outside of that block.
- teo_zero 11mo agoNo if you're allowed to only get an immutable reference from an immutable variable.