complement to $

Walter Bright newshound1 at digitalmars.com
Sat May 15 14:46:12 PDT 2010


bearophile wrote:
> KennyTM~:
>> auto a = new OrderedDict!(int, string);
>> a[-3] = "negative three";
>> a[-1] = "negative one";
>> a[0] = "zero";
>> a[3] = "three";
>> a[4] = "four";
>> assert(a[0] == "zero");
>> return a[0..4]; // which slice should it return?
> 
> D slicing syntax and indexing isn't able to represent what you can in Python, where you can store the last index in a variable:
> 
> last_index = -1
> a = ['a', 'b', 'c', 'd']
> assert a[last_index] == 'd'
> 
> In D you represent the last index as $-1, but you can't store that in a variable.

Sure you can:

     last_index = a.length - 1;


More information about the Digitalmars-d mailing list