digitalmars.D - array assignment overloading change to opIndexAssign()
- "Walter" <newshound digitalmars.com> Jun 09 2004
- J Anderson <REMOVEanderson badmama.com.au> Jun 09 2004
- "Walter" <newshound digitalmars.com> Jun 09 2004
- Stewart Gordon <smjg_1998 yahoo.com> Jun 10 2004
- Sean Kelly <sean f4.ca> Jun 10 2004
- "Walter" <newshound digitalmars.com> Jun 10 2004
- "Matthew" <matthew.hat stlsoft.dot.org> Jun 10 2004
- Sean Kelly <sean f4.ca> Jun 11 2004
- Norbert Nemec <Norbert.Nemec gmx.de> Jun 13 2004
- Kevin Bealer <Kevin_member pathlink.com> Jun 14 2004
- "Matthew" <admin stlsoft.dot.dot.dot.dot.org> Jun 14 2004
- Kevin Bealer <Kevin_member pathlink.com> Jun 15 2004
- Norbert Nemec <Norbert.Nemec gmx.de> Jun 15 2004
- Kevin Bealer <Kevin_member pathlink.com> Jun 15 2004
- "Ivan Senji" <ivan.senji public.srce.hr> Jun 16 2004
- Norbert Nemec <Norbert.Nemec gmx.de> Jun 16 2004
I'm going to change this to use opIndexAssign() rather than opIndex(); the
latter will now only be used as array rvalues. This is necessary to support
multi-index arrays. So, replace:
T opIndex(int index, V value) { ... }
with:
T opIndexAssign(V value, int index) { ... }
In fact, at the moment you can write both functions, use the same function
body, and have a smooth integration with the next DMD.
Jun 09 2004
Walter wrote:I'm going to change this to use opIndexAssign() rather than opIndex(); the latter will now only be used as array rvalues. This is necessary to support multi-index arrays. So, replace: T opIndex(int index, V value) { ... } with: T opIndexAssign(V value, int index) { ... } In fact, at the moment you can write both functions, use the same function body, and have a smooth integration with the next DMD.
-- -Anderson: http://badmama.com.au/~anderson/
Jun 09 2004
"J Anderson" <REMOVEanderson badmama.com.au> wrote in message news:ca81fl$rs6$1 digitaldaemon.com...Walter wrote:I'm going to change this to use opIndexAssign() rather than opIndex();
latter will now only be used as array rvalues. This is necessary to
multi-index arrays. So, replace: T opIndex(int index, V value) { ... } with: T opIndexAssign(V value, int index) { ... } In fact, at the moment you can write both functions, use the same
body, and have a smooth integration with the next DMD.
I'll do that if possible. In the meantime, this is just a heads-up.
Jun 09 2004
Walter wrote:I'm going to change this to use opIndexAssign() rather than opIndex(); the latter will now only be used as array rvalues. This is necessary to support multi-index arrays. So, replace: T opIndex(int index, V value) { ... } with: T opIndexAssign(V value, int index) { ... }
Why swap the arguments over? To confuse people? Or does it somehow simplify the extension to multi-indexes?In fact, at the moment you can write both functions, use the same function body, and have a smooth integration with the next DMD.
Or make one call the other. Is there going to be an opSliceAssign as well? Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
Jun 10 2004
In article <ca9q2r$gfg$1 digitaldaemon.com>, Stewart Gordon says...Walter wrote:I'm going to change this to use opIndexAssign() rather than opIndex(); the latter will now only be used as array rvalues. This is necessary to support multi-index arrays. So, replace: T opIndex(int index, V value) { ... } with: T opIndexAssign(V value, int index) { ... }
Why swap the arguments over? To confuse people? Or does it somehow simplify the extension to multi-indexes?
T opIndexAssign(V value, int index1, int index2, int index3, ...) {} :) Sean
Jun 10 2004
"Sean Kelly" <sean f4.ca> wrote in message news:ca9ulq$o30$1 digitaldaemon.com...In article <ca9q2r$gfg$1 digitaldaemon.com>, Stewart Gordon says...Walter wrote:I'm going to change this to use opIndexAssign() rather than opIndex();
latter will now only be used as array rvalues. This is necessary to
multi-index arrays. So, replace: T opIndex(int index, V value) { ... } with: T opIndexAssign(V value, int index) { ... }
Why swap the arguments over? To confuse people? Or does it somehow simplify the extension to multi-indexes?
T opIndexAssign(V value, int index1, int index2, int index3, ...) {}
Maybe it should be: T opIndexAssign(int index1, int index2, int index3, ... , V value) {}
Jun 10 2004
"Walter" <newshound digitalmars.com> wrote in message news:cabiqn$9a9$2 digitaldaemon.com..."Sean Kelly" <sean f4.ca> wrote in message news:ca9ulq$o30$1 digitaldaemon.com...In article <ca9q2r$gfg$1 digitaldaemon.com>, Stewart Gordon says...Walter wrote:I'm going to change this to use opIndexAssign() rather than opIndex();
latter will now only be used as array rvalues. This is necessary to
multi-index arrays. So, replace: T opIndex(int index, V value) { ... } with: T opIndexAssign(V value, int index) { ... }
Why swap the arguments over? To confuse people? Or does it somehow simplify the extension to multi-indexes?
T opIndexAssign(V value, int index1, int index2, int index3, ...) {}
Maybe it should be: T opIndexAssign(int index1, int index2, int index3, ... , V value) {}
I think value first is best
Jun 10 2004
In article <cabiqn$9a9$2 digitaldaemon.com>, Walter says...Maybe it should be: T opIndexAssign(int index1, int index2, int index3, ... , V value) {}
Assuming it's just as easy to parse either way, I prefer this method. It maintains consistency with opIndex and somehow seems clearer as it reads in the same order that the original statement is written. Would we lose anything by putting the value last? Sean
Jun 11 2004
Walter wrote:"Sean Kelly" <sean f4.ca> wrote in message news:ca9ulq$o30$1 digitaldaemon.com...In article <ca9q2r$gfg$1 digitaldaemon.com>, Stewart Gordon says...Walter wrote:I'm going to change this to use opIndexAssign() rather than opIndex();
latter will now only be used as array rvalues. This is necessary to
multi-index arrays. So, replace: T opIndex(int index, V value) { ... } with: T opIndexAssign(V value, int index) { ... }
Why swap the arguments over? To confuse people? Or does it somehow simplify the extension to multi-indexes?
T opIndexAssign(V value, int index1, int index2, int index3, ...) {}
Maybe it should be: T opIndexAssign(int index1, int index2, int index3, ... , V value) {}
Might there be any reason to use opIndexAssign with variadic arguments for some exotic data-structure? In that case, value-first might be the better solution.
Jun 13 2004
In article <cabiqn$9a9$2 digitaldaemon.com>, Walter says..."Sean Kelly" <sean f4.ca> wrote in message news:ca9ulq$o30$1 digitaldaemon.com...In article <ca9q2r$gfg$1 digitaldaemon.com>, Stewart Gordon says...Walter wrote:I'm going to change this to use opIndexAssign() rather than opIndex();
latter will now only be used as array rvalues. This is necessary to
multi-index arrays. So, replace: T opIndex(int index, V value) { ... } with: T opIndexAssign(V value, int index) { ... }
Why swap the arguments over? To confuse people? Or does it somehow simplify the extension to multi-indexes?
T opIndexAssign(V value, int index1, int index2, int index3, ...) {}
Maybe it should be: T opIndexAssign(int index1, int index2, int index3, ... , V value) {}
Depending on the future of multi-dim arrays, is there a need for: T opIndexAssign(Value V, int i1, int i2, int i3); // X3 T opIndexAssign(Value V, int i1, int i2); // X2 T opIndexAssign(Value V, int i1); // X1 .. on the same array? I.e. the X1 model would return a two-dim slice of the original? If so, maybe Value should be first for symmetry. Kevin
Jun 14 2004
"Kevin Bealer" <Kevin_member pathlink.com> wrote in message news:calav2$2lmo$1 digitaldaemon.com...In article <cabiqn$9a9$2 digitaldaemon.com>, Walter says..."Sean Kelly" <sean f4.ca> wrote in message news:ca9ulq$o30$1 digitaldaemon.com...In article <ca9q2r$gfg$1 digitaldaemon.com>, Stewart Gordon says...Walter wrote:I'm going to change this to use opIndexAssign() rather than opIndex();
latter will now only be used as array rvalues. This is necessary to
multi-index arrays. So, replace: T opIndex(int index, V value) { ... } with: T opIndexAssign(V value, int index) { ... }
Why swap the arguments over? To confuse people? Or does it somehow simplify the extension to multi-indexes?
T opIndexAssign(V value, int index1, int index2, int index3, ...) {}
Maybe it should be: T opIndexAssign(int index1, int index2, int index3, ... , V value) {}
Depending on the future of multi-dim arrays, is there a need for: T opIndexAssign(Value V, int i1, int i2, int i3); // X3 T opIndexAssign(Value V, int i1, int i2); // X2 T opIndexAssign(Value V, int i1); // X1 .. on the same array? I.e. the X1 model would return a two-dim slice of the original? If so, maybe Value should be first for symmetry.
Good point. Presumably the higher order overloads are slices, and the lowest is for accessing the actual cell/element?
Jun 14 2004
In article <calc77$2nf4$1 digitaldaemon.com>, Matthew says..."Kevin Bealer" <Kevin_member pathlink.com> wrote in message news:calav2$2lmo$1 digitaldaemon.com...In article <cabiqn$9a9$2 digitaldaemon.com>, Walter says..."Sean Kelly" <sean f4.ca> wrote in message news:ca9ulq$o30$1 digitaldaemon.com...In article <ca9q2r$gfg$1 digitaldaemon.com>, Stewart Gordon says...Walter wrote:I'm going to change this to use opIndexAssign() rather than opIndex();
latter will now only be used as array rvalues. This is necessary to
multi-index arrays. So, replace: T opIndex(int index, V value) { ... } with: T opIndexAssign(V value, int index) { ... }
Why swap the arguments over? To confuse people? Or does it somehow simplify the extension to multi-indexes?
T opIndexAssign(V value, int index1, int index2, int index3, ...) {}
Maybe it should be: T opIndexAssign(int index1, int index2, int index3, ... , V value) {}
Depending on the future of multi-dim arrays, is there a need for: T opIndexAssign(Value V, int i1, int i2, int i3); // X3 T opIndexAssign(Value V, int i1, int i2); // X2 T opIndexAssign(Value V, int i1); // X1 .. on the same array? I.e. the X1 model would return a two-dim slice of the original? If so, maybe Value should be first for symmetry.
Good point. Presumably the higher order overloads are slices, and the lowest is for accessing the actual cell/element?
If you mean X3 is highest, then yes. Kevin
Jun 15 2004
Kevin Bealer wrote:Depending on the future of multi-dim arrays, is there a need for: T opIndexAssign(Value V, int i1, int i2, int i3); // X3 T opIndexAssign(Value V, int i1, int i2); // X2 T opIndexAssign(Value V, int i1); // X1 .. on the same array? I.e. the X1 model would return a two-dim slice of the original? If so, maybe Value should be first for symmetry.
That depends very much on what kind of array you implement. The language-supported arrays that I'm proposing in my draft allow indexing and slicing only for exactly the same dimensionality as the array. For indexing only certain dimensions, you will have to do something like int[3,3,3] A = ...; int[3,3] B = A[1,,]; So for these arrays, the answer to your question would be "no". Anyhow: the overloaded opIndexAssign is meant to be flexible to be used in all kinds of data-structures. Who knows when somebody finds a use for different numbers of indices in some data-structure?
Jun 15 2004
In article <camr4m$1tfl$1 digitaldaemon.com>, Norbert Nemec says...Kevin Bealer wrote:Depending on the future of multi-dim arrays, is there a need for: T opIndexAssign(Value V, int i1, int i2, int i3); // X3 T opIndexAssign(Value V, int i1, int i2); // X2 T opIndexAssign(Value V, int i1); // X1 .. on the same array? I.e. the X1 model would return a two-dim slice of the original? If so, maybe Value should be first for symmetry.
That depends very much on what kind of array you implement. The language-supported arrays that I'm proposing in my draft allow indexing and slicing only for exactly the same dimensionality as the array. For indexing only certain dimensions, you will have to do something like int[3,3,3] A = ...; int[3,3] B = A[1,,]; So for these arrays, the answer to your question would be "no". Anyhow: the overloaded opIndexAssign is meant to be flexible to be used in all kinds of data-structures. Who knows when somebody finds a use for different numbers of indices in some data-structure?
If you don't like them or can't support them, don't implement them, and the corresponding slicing operation becomes forbidden. This is analagous to current language definitions, where you opt to support comparisons by defining opCmp, etc. In my proposed syntax, I was assuming that a 5x10x20 array would not produce a 3x3 array no matter how you slice it. You either slice out a 10x20 or a 5x10, or a 5 or a 20, depending on how many layers you peel off and whether it is a column-first or row-first implementation. Column versus row ordering would be determined by the implementor or the language and would determine whether you get the first N indices or the last N when you slice and dice. Kevin
Jun 15 2004
"Kevin Bealer" <Kevin_member pathlink.com> wrote in message news:cans7t$fl1$1 digitaldaemon.com...In article <camr4m$1tfl$1 digitaldaemon.com>, Norbert Nemec says...Kevin Bealer wrote:Depending on the future of multi-dim arrays, is there a need for: T opIndexAssign(Value V, int i1, int i2, int i3); // X3 T opIndexAssign(Value V, int i1, int i2); // X2 T opIndexAssign(Value V, int i1); // X1 .. on the same array? I.e. the X1 model would return a two-dim slice
the original? If so, maybe Value should be first for symmetry.
That depends very much on what kind of array you implement. The language-supported arrays that I'm proposing in my draft allow indexing
slicing only for exactly the same dimensionality as the array. For
only certain dimensions, you will have to do something like int[3,3,3] A = ...; int[3,3] B = A[1,,]; So for these arrays, the answer to your question would be "no". Anyhow:
overloaded opIndexAssign is meant to be flexible to be used in all kinds
data-structures. Who knows when somebody finds a use for different
of indices in some data-structure?
If you don't like them or can't support them, don't implement them, and
corresponding slicing operation becomes forbidden. This is analagous to
language definitions, where you opt to support comparisons by defining
Not true! opCmp is not an option, when you write a class you get it (want it or not). Couldn't resist to mention opCmp(and opEquals) topic again :)etc. In my proposed syntax, I was assuming that a 5x10x20 array would not
3x3 array no matter how you slice it. You either slice out a 10x20 or a
or a 5 or a 20, depending on how many layers you peel off and whether it
column-first or row-first implementation. Column versus row ordering
determined by the implementor or the language and would determine whether
get the first N indices or the last N when you slice and dice. Kevin
Jun 16 2004
Kevin Bealer wrote:In my proposed syntax, I was assuming that a 5x10x20 array would not produce a 3x3 array no matter how you slice it. You either slice out a 10x20 or a 5x10, or a 5 or a 20, depending on how many layers you peel off and whether it is a column-first or row-first implementation. Column versus row ordering would be determined by the implementor or the language and would determine whether you get the first N indices or the last N when you slice and dice.
My multidim-Array proposal is more flexible. You can mix slicing and partial indexing in one expression: int[[4]] A = new int[5,10,20,2]; int[[3]] B = A[2,1..7:2,5..6,]; Here, the first dimension is indexed, to the resulting array has one dimension less. The second and the third dimension are both sliced. The second one with stride 2, so it leaves three entries (1,3 and 5) the second one leaves range 1. The last dimension is left untouched. The result would be an 3x1x2 array. Row versus column ordering is handled fully transparently to the programmer. The default is Fortran-style alignment, but you can just as well create a C-style array in memory. The user of an array does not need to think about the memory layout. For more details, see http://homepages.uni-regensburg.de/~nen10015/documents/D-multidimarray.html Ciao, Nobbi
Jun 16 2004









"Walter" <newshound digitalmars.com> 