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

Stewart Gordon smjg_1998 at yahoo.com
Thu Nov 22 07:01:08 PST 2007


"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.

-- 
My e-mail address is valid but not my primary mailbox.  Please keep replies 
on the 'group where everybody may benefit. 




More information about the Digitalmars-d mailing list