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.
Re:Nim in 2018: A short recap
by bunderbunder on Wednesday January 09, 2019 @11:33AM
(#18866042)
I 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.
Re:Nim in 2018: A short recap
by atilaneves on Wednesday January 09, 2019 @12:35PM
(#18866732)
I 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.
How does Nim prevent modifying an object after it has been added to a Table? (Or is it always copied?)
It's also what allows Python to do interning of strings, since they can't change.