DMD 0.177 release [Length in slice expressions]
Oskar Linde
oskar.lindeREM at OVEgmail.com
Thu Dec 21 05:26:36 PST 2006
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]
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
The resulting code becomes quite optimal without the need for a position
dependent opLength type of operator, but handling all the cases puts a
larger burden on the implementor of opIndex.
> The problem is that opSlice has to look like opSlice(T1 lo, T2 hi) right
> now -- just two parameters (or zero).
[snip]
> Another solution is a built-in slice type. Ranges like a..b would get
> converted to slice instances automatically.
Yes, this would be my suggestion too. Adding an opApply to one such
built in range type would also have the nice side effect of allowing the
syntactical sugar:
foreach(i; 5..10)
> --User Definable '$'--
[snip]
> One solution - make an opLength that gets called with the parameter
> number in which the $ appears.
Yes, that is probably the cleanest solution. And if no such
opLength(int) overload exists, return the result of opLength() (or
possibly .length)
/Oskar
More information about the Digitalmars-d-announce
mailing list