Array indexing and slicing
Derek Parnell
derek at psych.ward
Mon Apr 3 18:45:09 PDT 2006
On Mon, 3 Apr 2006 22:47:37 +0000 (UTC), Luís Marques wrote:
> $ is shorter than .length
One problem with 'length' is that is not a keyword in all contexts, and so
an innocent coding mistake such as the one below can occur and is
manifested at run time. And even then its not so easy to see if you're not
focusing on 'length'.
import std.stdio;
void main()
{
int length;
char[] foo;
foo = "derek parnell".dup;
length = 4;
while( foo[length] != 'a' )
foo = foo[1..$];
writefln("%s", foo);
}
--
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Down with mediocracy!"
4/04/2006 11:40:09 AM
More information about the Digitalmars-d
mailing list