DMD 0.177 release [Length in slice expressions]

Bill Baxter dnewsgroup at billbaxter.com
Thu Dec 21 16:46:32 PST 2006


Bill Baxter wrote:
> Andrei Alexandrescu (See Website For Email) wrote:
> 

> Then of course the next step is to have a parameter number automatically 
> passed to the length method given and expression like a[$-1,$-1] so that
>     a[$-1,$-1]
>     ==>  a[$[0]-1,$[1]-1]
>     ==>  a[a$[0]-1,a$[1]-1]
>     ==>  a[a.length[0],a.length[1]]

Slight typo there.  Last line should of course have been:

       ==>  a[a.length[0]-1,a.length[1]-1]

> The compiler can decide whether to do indexing or not based on whether 
> .length results in an indexable value.
> 
> Finally, in general I think the choice of name 'length' is unfortunate 
> because of it's implication of linearity.  But it's not too late.  If $ 
> becomes associated with .size rather than .length in user types then 
> everything will be ok.  For built-in arrays .length can become a synonym 
> for .size, just as it is with std::string in C++.  C++/STL got this one 
> right.  For generic containers .size is a much better name.

Another thing which occurred to me is that if the meaning of $ becomes 
tied to "size" rather than "length", then then you also have the 
mnemonic of $ looking like an 's' as in 'size'.

I also still think making it a postfix operator makes sense.

--bb



More information about the Digitalmars-d-announce mailing list