Nested slicing

Koroskin Denis 2korden+dmd at gmail.com
Tue Apr 1 09:31:09 PDT 2008


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;
}

What do you bet it will yield?



More information about the Digitalmars-d mailing list