Proposal: Make [][x] and [][a..b] illegal (reserve for multidimensional arrays)

Bill Baxter dnewsgroup at billbaxter.com
Thu Nov 22 12:53:49 PST 2007


Janice Caron wrote:
> I had a mad thought yesterday. It probably won't fly, but...
> 
> what if opSlice took tuple arguments, like this
> 
>     a[3,4 .. 5,6]

Actually, you can definitely already have a similar syntax if you want it:

       a[[3,4] .. [5,6]]

The problem is that nobody does.  :-)

It's hard to see what's going on with the uppers and lowers grouped 
together, rather than each dim.  Your eyes have to go back and forth 
trying to pair up this with that.


> translating to
> 
>     a.opSlice(Tuple!(3,4),Tuple!(5,6))
> 
> implying the slice [3..5] in one dimension, and [4..6] in a second.
> That would kind of automatically give you a syntax for
> multidimensional arrays. Of course it would help if length() also took
> tuples...
> 
>     a.length = Tuple!(3,3); /* create a 3x3 array */
> 
>     Tuple!(int,int) dims = a.length; /* get the array dimensions */
> 
> I suspect it might be possible to implement this right now in
> user-defined classes by suitably overloading opSlice(),
> opSliceAssign() and length().
> 
> There's probably some reason why it wouldn't work that I haven't thought of. :-)


--bb



More information about the Digitalmars-d mailing list