3 ms·
Nim gives you the choice of whether something is immutable or not. A `Table[T, Y]` (Nim's dictionary type) simply doesn't allow the key to be modified, no matte
by dom96 8y ago
Nim gives you the choice of whether something is immutable or not. A `Table[T, Y]` (Nim's dictionary type) simply doesn't allow the key to be modified, no matter what the key type is.
- bunderbunder 8y agoI think this is really what it comes down to in Nim. I personally prefer immutable strings, but I don't think it would be wise to force them to always be immutable in Nim, because then you'd have this weird language wart where let foo = someValue var bar = someOtherValue yields an immutable foo and a mutable bar for all types except strings. I'm guessing that's a detail that's lost on folks who haven't spent much time with Nim, because the way mutability and immutability work in Nim is different from how it works in any mainstream language.
- atilaneves 8y agoI don't know a lot about Nim, but I do know D, and there `string` is just an alias to `immutable(char)[]`. String literals are of this type. But one can manipulate mutable arrays of char all day long if needed.
- shalabhc 8y agoHow does Nim prevent modifying an object after it has been added to a Table? (Or is it always copied?)
- dom96 8y agoA string will be copied if stored in a Table.