3 ms·
> How could you mutate a variable in a way that this language disallows? I presume something like this: array a = [1, 2, 3] a.append(4) Names are mut
by ben-schaaf 7y ago
> How could you mutate a variable in a way that this language disallows?
I presume something like this:
array a = [1, 2, 3]
a.append(4)
Names are mutable, but the values they point to are not.
- cnasc 7y agoI think something more like a[0] = 1 Would be a better example. Appending to an array could involve creating a new array and reassigning it to ‘a’.
- catlifeonmars 7y agoThe getting started guide demonstrates that arrays are mutable. https://chaos-lang.org/docs/05_arrays https://chaos-lang.org/docs/05_arrays
- abiogenesis 7y agoYet it says [1]: > Arrays and the elements of arrays are also immutable I guess the docs need a bit of rewording. Forcing a deep-copy on variable assignment does not mean the variable itself is immutable. [1] https://chaos-lang.org/docs/07_immutability https://chaos-lang.org/docs/07_immutability
- catlifeonmars 7y agoAh, I did not dive that deep. Now I am curious what the impact of deep copies on performance is, and if the language employs any clever optimizations to improve performance.
- abiogenesis 7y agoI don't see how you can reliably deep copy any user defined class either.
- lgessler 7y agoThere are none, at least in the familiar OOP sense: > Chaos language is not object-oriented. So everything is done by functions and data types.
- deleted 7y ago[deleted]
- agentultra 7y agoTurns out that immutable data structures can share a lot of structure safely. https://www.amazon.com/Purely-Functional-Structures-Chris-Okasaki-ebook/dp/B00AKE1V04 https://www.amazon.com/Purely-Functional-Structures-Chris-Ok...
- catlifeonmars 7y agoAs an aside, rebinding local references can be viewed as a form of mutability.