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

Don Clugston dac at nospam.com.au
Thu Nov 22 01:48:28 PST 2007


Bill Baxter wrote:
>> Curiously,  float[3,4] a; is legal, (and is equivalent to float [4] a;)
>> but a[2,3]
>> generates:
>>  Error: only one index allowed to index float[4u]
>>
>> which is a pretty strong indicator that Walter intends to support 
>> [i,j,k] syntax at some point.
> 
> There's more than just intent.  It works fine.  Write yourself an 
> opIndex(int,int,int) and try it out.  opIndexAssign(Value v, 
> int,int,int) type things work too.  opIndex(MyStruct,Object,Object) even 
> works.   The hole in functionality right now is just in the intersection 
> of multiple indices and slices.  But since you can have Object/struct 
> indices you can create your slicing scheme using a custom Slice type for 
> indices.  You just can't have $ or .. syntax (at least .. in any other 
> form than foo[A..B].

Cool! I have no idea how I missed that. (My Blade syntax parser even supports 
it, and has unit tests for it(!) -- man I feel like an idiot <g>)

So in theory, all we need is a standard slice/range container (for indices), and
uint opDollar(uint dimension)?
Presumably, opDollar and slices only make sense for integral indices? (Could be 
stretched to include reals, but the concept does require a total ordering, so 
couldn't even include complex types).

Plus it should probably work for built-in arrays (recognising that at present, 
most slicing operations would be unsupported).



More information about the Digitalmars-d mailing list