Why do programming languages like Ruby use symbols? I understand that String manipulation is much slower than using a lookup table as well as the idea that Strings are reallocated in memory no matter if it is the same or different as one used previously, but can't interpreters compensate for this? It would seem like an interpreter still has to parse the word that you typed in order to match it to a symbol, so why not just do the same with a string object?
For instance, why doesn't the compiler take:
myHash["myKey"] = ...
and treat it as
myHash[:myKey] = ...
behind the scenes, anyways? Even if the key is dynamic - it's an interpreter, so should it not know what the key is going to be before it finds the value and still treat the string key as a symbol? eg.:
concatMe = "Key" myHash["my" + concatMe] = ...
How come an interpreter can't still treat this as
If it knows what
"my" + concatMe
is before it finds the value by key?