Perhaps the right thing to do here then is to make replace accept a range of characters to replace:
str = "I am a scientist" replace(str,8:16,"scholar") ? On Fri, Mar 21, 2014 at 5:21 PM, Milan Bouchet-Valat <[email protected]>wrote: > Le samedi 22 mars 2014 à 05:08 +0800, cnbiz850 a écrit : > > Well, from this perspective, it makes sense why those strings should not > > be mutable. > > > > But from other perspectives, making strings immutable contradicts with > > how natural languages are used. For instance, after I said "I am a > > professor", I want to say "I am a scientist", or perhaps I change my > > mind and say "I am a scholar". > But when it comes to concretely changing "I am a scientist" to "I am a > scholar", you'll do this anyway: > replace("I am a scientist", "scientist", "scholar") > > I really doubt you'll find plausible use cases where you'd prefer to > mutate the string. And guess what, a construct like this couldn't work: > str = "I am a scientist" > str[8:16] = "scholar" > > because the replacement string is too short. Woops... > > > So the question of whether the string is mutable or not has no serious > practical consequences. > > > Regards >
