Array start index

DLearner via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Aug 3 14:32:03 PDT 2015


On Monday, 3 August 2015 at 13:45:01 UTC, bachmeier wrote:
> On Sunday, 2 August 2015 at 21:58:48 UTC, QAston wrote:
>
>> Adding 1-indexed arrays to the language fixes nothing. Just 
>> write your 1-indexed array type and if you enjoy using it, 
>> publish it as a library. Who knows, if demand is high it may 
>> even end up in phobos.
>
> Oh, I don't think that's a good idea. It's too confusing to 
> have more than one method of indexing within the same language. 
> You just have to do a thorough job of testing, as the 
> possibility of errors is something you'll have to live with, 
> given the different design choices of different languages.

Looks like 0-base is fixed, to avoid problems with existing code.

But nothing stops _adding_ to the language by allowing
int[x:y] foo to mean valid symbols are foo[x], foo[x+1],..., 
foo[y].
Plus rule that int[:y] means valid symbols are foo[1], 
foo[2],..., foo[y].

That way, 1-start achieved, with no conflict with existing code?



More information about the Digitalmars-d-learn mailing list