Lars T. Kyllingstad wrote:
Don wrote:
Norbert Nemec wrote:
Don wrote:
Norbert Nemec wrote:
Hi there,

in implementing multi-dimensional arrays, the current way of overloading the slicing operator does not scale up.

Currently, there is opIndex working for an arbitrary number of indices, but opSlice works only for one dimension. Ultimately, it should be possible to allow slicing for more than one dimension, and mixing it with indexing for e.g.:
    A[4,7..8,7,2..5]
So far, no clean solution for overloading this has been suggested.

A solution was suggested while you were away.
You don't need a new opRange operator, a simple tuple struct like:
struct Slice(T) { T from; T to; }
in std.object is enough.
Note that:
A[4, Slice(7,8), 7, Slice(2,5)]

will work with the existing compiler. So it's just a tiny syntax sugar issue.

I know this solution. It is exactly the "syntax sugar" issue that I see as the problem here:

The compiler would need to be aware of the data type Slice. It would therefore have to be something like a "builtin" type. If I am not mistaken, the language definition so far never makes use of "builtin" struct types.

You are mistaken <g>.
object, TypeInfo, AssociativeArray, ...
Complex will be added to that list, too.

It will?  For complex literals, then?

-Lars
Hmmm. Maybe not. Complex literals will probably just disappear. We don't need them any more.

Reply via email to