Actually, Strings are already immutable. Well, mostly. You can't change a
string directly, but you can (but generally shouldn't) modify the backing
array.

Given that, I don't know why indexing couldn't return a substring, although
there might be reasons--e.g., calling C code is possible with ASCIIStrings
or UTF8Strings, but SubStrings have to be copied and null-terminated (I
think this already happens).

Anyway, all of the ideas below would be good to raise in an issue (if there
isn't one). The documentation of SubString at least needs to be done.

Cheers, Kevin

On Wednesday, June 11, 2014, <[email protected]> wrote:

>
>> One thought, it might be nice to have something a little more automatic.
>> Specifically, I was thinking if there was an 'ImmutableString' class, you
>> would always know that you should make a view rather than a copy. It would
>> also be in keeping with the general design where specifying a type allows
>> the compiler to do nice optimizations.
>>
>
> I guess that won't be the case to keep types stable. A slice of
> ImmutableString should remain an ImmutableString.
>
> However, SubString (and SubArray) could be changed so that the indices are
> made optional. You could write
> s = SubString(randstring(size))
> and handle it with views.
>
>

Reply via email to