Array start index

QAston via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Aug 4 04:29:07 PDT 2015


On Monday, 3 August 2015 at 21:32:05 UTC, DLearner wrote:
> 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?

There're quite a few things stopping this from being added to the 
language.

1. People will have to learn this new feature and it's 
interaction with gazillion of other D features.

2. There would be a redundancy - core language will have 2 array 
types while one of them can be easily implemented using the other.

3. Devs will have to maintain it - as if they don't have enough 
things to fix atm.

Really, this is so simple to do as a library - just use opIndex, 
opSlice with a template struct.

As a general rule - start asking for language features only when 
things can't be done without them.


More information about the Digitalmars-d-learn mailing list