Proposal: Make [][x] and [][a..b] illegal (reserve for multidimensional arrays)
Don Clugston
dac at nospam.com.au
Thu Nov 22 11:06:12 PST 2007
Oskar Linde wrote:
> Bill Baxter wrote:
>> Oskar Linde wrote:
>>> Bill Baxter wrote:
>>>
>>>> Anyway, f[i][j][k] syntax is much more difficult to read than
>>>> f[i,j,k]. So I think the latter is what we should be shooting for.
>>>
>>> I agree, and for what it is worth it is possible to implement
>>> multidimensional indexing and slicing for UDTs today. The only thing
>>> lacking is the ability to use the .. and $ tokens. For example:
>>>
>>> f[i, all, all, j, all, end-1, all, range(1, end)]
>>>
>>> gets translated into quite optimal code. The only variables that get
>>> passed to the indexing function is (i,j,1,1) and no temporaries need
>>> to be created. I guess that with some additional compiler supported
>>> sugaring, the above could become something like:
>>>
>>> f[i, .. , .. , j, .. , $-1, .. , 1..$]
>>>
>>
>> Now if you would just put all that goodness on Dsource or somewhere
>> where the rest of us can appreciate it... :-)
>
> OK. I extracted it from my sources, stripping it from most external
> dependencies. Operator overloading is also stripped and most
> non-essentials:
>
> http://www.csc.kth.se/~ol/multiarray.zip
>
> The result is basically a simple demonstration of a strided
> multidimensional array slice type.
>
> Indexing/slicing is done in such a way that:
>
> f[a,b,c] is identical to
> f[a][b][c]
> f[a,b][c]
> f[a][b,c]
>
> Don's global __dollar idea is implemented, but not int[2] slices (can't
> do them easily as things are now).
Would be nice to know if that __dollar behaviour is a
half-finished/unannounced/forgotten feature by Walter, or just a bug. I suspect
it's an Easter egg. I wonder how long it's been there.
Walter, care to comment on this?
Simply adding a line into std.object would make it a standard feature. We can
road-test it first.
More information about the Digitalmars-d
mailing list