←back to thread

498 points azhenley | 2 comments | | HN request time: 0s | source
Show context
sunrunner ◴[] No.45770373[source]
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.
replies(2): >>45770571 #>>45770594 #
1. pizza234 ◴[] No.45770571[source]
This is in essence a mutable borrow - by looking at Rust's borrow checker, one can see the complexities of the concept.
replies(1): >>45771320 #
2. danenania ◴[] No.45771320[source]
Clojure has transients—a similar idea I believe. Basically bounded mutation.