Array indexing and slicing
Norbert Nemec
Norbert at Nemec-online.de
Mon Apr 3 15:13:50 PDT 2006
The "length" variant will become problematic once we have
multidimensional arrays, where the integer number "length" is replaced
by an integer array "shape". "$" can be given a very special meaning by
the compiler without problems for the parser, allowing
somearray[1..$-1,1..$-1,1..$-1]
to mean the same thing as
somearray[1..shape[0]-1,1..shape[1]-1,1..shape[2]-1]
to get the same effect with using "length" instead of "$", the word
"length" would probably have to become a keyword, which would disallow
its use as property. (Unless you really want to mess up the parser...)
Greetings,
Norbert
Hong wrote:
> In article <e0rmga$1bi6$1 at digitaldaemon.com>, Lu疄 Marques says...
>
>
>>notation and someting you'd expect to find in Perl. I still prefer it to the
>>more verbose "a[2 .. a.length]" notation, though. The verbose notation has the
>>disadvantage of taking more whitespace; while most people read "a[2..3]" just
>>fine it's a bit confusing to read "a[1..a.length]". Also, if you rename or use a
>>different array you have two instances to correct, instead of one.
>>
>
>
> You can do a[1..length]. length always refer to the array length when it is used
> inside the indexing operator. So there is only 1 place to correct when you
> change the array name. length is more verbose but definitely more readable.
>
>
More information about the Digitalmars-d
mailing list