DMD 0.177 release [Length in slice expressions]

Bill Baxter dnewsgroup at billbaxter.com
Sun Dec 24 19:30:56 PST 2006


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.

> 
> Basicly, the transformation is:
> 
> $ => end
> a..b => range(a,b)
> 
> I briefly described this in:
> news://news.digitalmars.com:119/eft9id$2aq3$1@digitaldaemon.com

Thanks for the link.  The 'end' thing isn't so bad, at least for a 
former Matlab user. :-)


--bb



More information about the Digitalmars-d-announce mailing list