Nested slicing

Derek Parnell derek at psych.ward
Tue Apr 1 13:53:23 PDT 2008


On Tue, 01 Apr 2008 20:31:09 +0400, Koroskin Denis wrote:

> On Mon, 31 Mar 2008 17:59:21 +0400, Koroskin Denis <2korden+dmd at gmail.com>  
> wrote:
> 
>> One last thing about dollar notation in array slicing.
>> Shouldn't the following piece of code generate a compile-time error?
>>
>> import std.stdio;
>>
>> int main()
>> {
>>      int[] outer = [0, 1, 2, 3, 4];
>>      int[] inner = [5, 4, 3, 2, 1];
>>
>>      int[] slice = outer[0..inner[$-1]]; < Error: shadowing declaration  
>> __dollar is deprecated
>>
>>      writefln(slice.length);
>>
>>      return 0;
>> }
> 
> This code might be ok. How about this one:
> 
> import std.stdio;
> 
> int main()
> {
>      int[] inner = [0, 1, 2, 3, 4];
>      int[] outer = [5, 4, 3, 2, 1];
> 
>      int[] slice = outer[$-1..inner[$-1]];	// now this _is_ shadowing!
> 
>      writefln(slice.length);
> 
>      return 0;
> }

Is it any more shadowing than ...

    int[] slice = outer[outer.length-1 .. inner[inner.length-1]];

which is its long-hand equivalent? 


-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell



More information about the Digitalmars-d mailing list