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

Don Clugston dac at nospam.com.au
Thu Nov 22 07:11:31 PST 2007


Stewart Gordon wrote:
> "Don Clugston" <dac at nospam.com.au> wrote in message 
> news:fi1c45$28gh$1 at digitalmars.com...
>>> Bill Baxter wrote:
>>>>> 2) D lacks a clean syntax for slices of multiple dimensions.  opSlice
>>>>> calls must have one and only one ".."
>>>>
>>>> Can you propose a syntax for that?
>>
>> How about making [] more than just a shorthand for [0..$], but rather 
>> mean "take everything from this dimension and move on".
>> This would, I think, make it more consistent with its usage in 
>> declarations, where it is a dimension marker, not a slice.
> <snip>
> 
> I'm not sure how this would work more generally, if you know what I 
> mean. AIUI when/if we get real multidimensional arrays, the syntax would be
> 
>    array[1..5, 2]
> 
> rather than
> 
>    array[1..5][2]
> 
> Moreover, the semantics you propose can lead to some even more 
> counter-intuitive notation than we have already.  You'd get such things as
> 
>    array[1..5][][2][6..10][][][4]
> 
> and while it's true that you could determine the dimension each applies 
> to by counting the []s without .. in them, probably even more people 
> than already would slip up and try something like
> 
>    array[1..6][7..10]
> 
> expecting it to take a rectangular slice.
> 
> Another way it could be defined is that any slicing operation on a 
> multidimensional array would cycle the dimensions, but I'm not sure if 
> that's desirable either.
> 
> Stewart.
> 
I've already retracted this proposal. And (with Oskar and Bill) discovered that 
the syntax
array[ 5, [1,$-5], 2, $-2]
is already possible. So we're 90% of the way there already.



More information about the Digitalmars-d mailing list