DMD 0.177 release [Length in slice expressions]

Reiner Pope xxxxxx at xxx.xx
Sun Dec 24 20:54:29 PST 2006


Bill Baxter wrote:
> Oskar Linde wrote:
>> Bill Baxter wrote:
>>> After trying to write a multi-dimensional array class, my opinion is 
>>> that D slice support could use some upgrades overall.
>>
>> I'd be very interested in looking at what you've come up with. With my 
>> own implementation of a multi-dimensional array type a couple of 
>> months ago, I came to the same conclusion. I posted about it in:
>>
>> news://news.digitalmars.com:119/edrv0n$hth$1@digitaldaemon.com
>> http://www.digitalmars.com/d/archives/digitalmars/D/announce/4717.html
>>
>>> What I'd like to see:
>>>
>>> --MultiRange Slice--
>>> * A way to have multiple ranges in a slice, and a mix slice of and 
>>> non-slice indices:
>>>     A[i..j, k..m]
>>>     A[i..j, p, k..m]
>> (snip)
>>  >      A[0..$,3..$]
>>
>> Yes, I would too. It is quite frustrating having the syntax in the 
>> language but not being allowed to utilize it... :)
>>
>> I work around this by instead using a custom slice syntax instead:
>>
>> A[range(i,j), range(k,m)]
>> A[range(i,j), p, range(k,m)]
>> A[range(0,end), range(3..end)]
>> A[end-1, p % end]
> 
> Yeh, that's similar to what I'm doing too.  But it's pretty ugly.  So I 
> guess that means you're using opIndex for everything and leaving opSlice 
> alone.  Are you able to have ranges return arrays and specific indexes 
> return scalar values that way?  That seems to me a big reason for having 
> opSlice exist in the first place.  The .. in the brackets not only means 
> you're slicing, it also means the function should return another array, 
> versus returning an element.  That seems like a nice distinction to have 
> to me.
> 
Is there anything particularly wrong with having foo[a..b,c,d..$] being 
syntactical sugar for foo[a..b][c][d..$] ? That way, I would imagine you 
could implement slicing and indexing of multidimensional arrays quite 
easily because, as Norbert Nemec said, indexing just returns an array 
with dimension reduced by one, and slicing returns an array of the same 
dimension, but perhaps different size. It also seems to allow any 
combination of slicing and indexing without needing variadic functions.



More information about the Digitalmars-d-announce mailing list