digitalmars.D - Nested slicing
- Koroskin Denis (13/13) Mar 31 2008 One last thing about dollar notation in array slicing.
- Janice Caron (4/6) Mar 31 2008 I hope not.
- Koroskin Denis (4/10) Mar 31 2008 My bet it should. This is both confusing and could be a source of errors...
- Jason House (2/19) Mar 31 2008 Absolutely! Shadowed variable declarations can be a tough thing to spot...
- Koroskin Denis (15/27) Apr 01 2008 On Mon, 31 Mar 2008 17:59:21 +0400, Koroskin Denis <2korden+dmd@gmail.co...
- Derek Parnell (8/44) Apr 01 2008 Is it any more shadowing than ...
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 =3D [0, 1, 2, 3, 4]; int[] inner =3D [5, 4, 3, 2, 1]; int[] slice =3D outer[0..inner[$-1]]; < Error: shadowing declaratio= n = __dollar is deprecated writefln(slice.length); return 0; }
Mar 31 2008
On 31/03/2008, Koroskin Denis <2korden+dmd gmail.com> wrote:One last thing about dollar notation in array slicing. Shouldn't the following piece of code generate a compile-time error?I hope not. (And even if it does, the error message should mention $, not __dollar, since __dollar is undocumented).
Mar 31 2008
On Mon, 31 Mar 2008 18:04:53 +0400, Janice Caron <caron800 googlemail.com> wrote:On 31/03/2008, Koroskin Denis <2korden+dmd gmail.com> wrote:My bet it should. This is both confusing and could be a source of errors. And it is a shadowing indeed.One last thing about dollar notation in array slicing. Shouldn't the following piece of code generate a compile-time error?I hope not. (And even if it does, the error message should mention $, not __dollar, since __dollar is undocumented).
Mar 31 2008
Koroskin Denis 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; }Absolutely! Shadowed variable declarations can be a tough thing to spot when things aren't working right. I'd just say to use outer.length or inner.length to resolve ambiguity.
Mar 31 2008
On Mon, 31 Mar 2008 17:59:21 +0400, Koroskin Denis <2korden+dmd gmail.co= m> = 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 =3D [0, 1, 2, 3, 4]; int[] inner =3D [5, 4, 3, 2, 1]; int[] slice =3D outer[0..inner[$-1]]; < Error: shadowing declarat=ion =__dollar is deprecated writefln(slice.length); return 0; }This code might be ok. How about this one: import std.stdio; int main() { int[] inner =3D [0, 1, 2, 3, 4]; int[] outer =3D [5, 4, 3, 2, 1]; int[] slice =3D outer[$-1..inner[$-1]]; // now this _is_ shadowing!= writefln(slice.length); return 0; } What do you bet it will yield?
Apr 01 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 gmail.com> wrote: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.parnellOne 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; }
Apr 01 2008