digitalmars.D - setting values of an array
- clayasaurus (11/11) Jun 14 2004 hey, right now i'm using a function like this
- Charlie (6/17) Jun 14 2004 array ~= x;
- clayasaurus (5/29) Jun 14 2004 it is just so much nicer to be able to set the contents of an array
- Regan Heath (16/51) Jun 14 2004 No idea.. it works for char[] eg.
- Regan Heath (10/45) Jun 14 2004 To answer this... Yes and No, it's because it's tricky and Walter has no...
- Ivan Senji (3/38) Jun 14 2004 Hopefully D will have this one day.
- J Anderson (8/13) Jun 15 2004 Although I haven't heard anything from Walter, I think this is just one
- Stewart Gordon (11/15) Jun 15 2004 Or
- Ivan Senji (6/21) Jun 15 2004 But this isn't good when you don't want a const array.
-
Stewart Gordon
(9/17)
Jun 15 2004
hey, right now i'm using a function like this to set a dynamic array's properties int[] array; set3array(array,1,2,3); void set3array(inout ALfloat[] array, float x, float y, float z) { array.length = 3; array[0] = x; array[1] = y; array[2] = z; } is there a better way to set array values than this?
Jun 14 2004
array ~= x; array ~= y; array ~= z; ? C In article <cal65o$2e3b$1 digitaldaemon.com>, clayasaurus says...hey, right now i'm using a function like this to set a dynamic array's properties int[] array; set3array(array,1,2,3); void set3array(inout ALfloat[] array, float x, float y, float z) { array.length = 3; array[0] = x; array[1] = y; array[2] = z; } is there a better way to set array values than this?
Jun 14 2004
it is just so much nicer to be able to set the contents of an array in one line. I like the C way: array[] = {1,2,3}; is there a good reason why D doesn't have this? In article <cal6us$2fab$1 digitaldaemon.com>, Charlie says...array ~= x; array ~= y; array ~= z; ? C In article <cal65o$2e3b$1 digitaldaemon.com>, clayasaurus says...hey, right now i'm using a function like this to set a dynamic array's properties int[] array; set3array(array,1,2,3); void set3array(inout ALfloat[] array, float x, float y, float z) { array.length = 3; array[0] = x; array[1] = y; array[2] = z; } is there a better way to set array values than this?
Jun 14 2004
On Mon, 14 Jun 2004 22:57:57 +0000 (UTC), clayasaurus <clayasaurus_member pathlink.com> wrote:it is just so much nicer to be able to set the contents of an array in one line. I like the C way: array[] = {1,2,3}; is there a good reason why D doesn't have this?No idea.. it works for char[] eg. char[] foo = "regan was here"; foo = "bob was here"; probably due to "regan was here" being converted to a char[] implicitly. This also works... ubyte[] b; b = cast(ubyte[])x"010203"; (sets b[0] to 1, b[1] to 2, and b[2] to 3) but is probably dependant on the endian-ness of the system it is compiled on? I tried to get one like the above working for float, but could not seem to. ReganIn article <cal6us$2fab$1 digitaldaemon.com>, Charlie says...-- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/array ~= x; array ~= y; array ~= z; ? C In article <cal65o$2e3b$1 digitaldaemon.com>, clayasaurus says...hey, right now i'm using a function like this to set a dynamic array's properties int[] array; set3array(array,1,2,3); void set3array(inout ALfloat[] array, float x, float y, float z) { array.length = 3; array[0] = x; array[1] = y; array[2] = z; } is there a better way to set array values than this?
Jun 14 2004
On Mon, 14 Jun 2004 22:57:57 +0000 (UTC), clayasaurus <clayasaurus_member pathlink.com> wrote:it is just so much nicer to be able to set the contents of an array in one line. I like the C way: array[] = {1,2,3}; is there a good reason why D doesn't have this?To answer this... Yes and No, it's because it's tricky and Walter has not yet implemented it. I believe this is called an "Array literal", your example above is un-ambiguous, but, there are several which are. See the other posts in this NG about array literals. ReganIn article <cal6us$2fab$1 digitaldaemon.com>, Charlie says...-- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/array ~= x; array ~= y; array ~= z; ? C In article <cal65o$2e3b$1 digitaldaemon.com>, clayasaurus says...hey, right now i'm using a function like this to set a dynamic array's properties int[] array; set3array(array,1,2,3); void set3array(inout ALfloat[] array, float x, float y, float z) { array.length = 3; array[0] = x; array[1] = y; array[2] = z; } is there a better way to set array values than this?
Jun 14 2004
"clayasaurus" <clayasaurus_member pathlink.com> wrote in message news:calahl$2l33$1 digitaldaemon.com...it is just so much nicer to be able to set the contents of an array in one line. I like the C way: array[] = {1,2,3}; is there a good reason why D doesn't have this?Hopefully D will have this one day.In article <cal6us$2fab$1 digitaldaemon.com>, Charlie says...array ~= x; array ~= y; array ~= z; ? C In article <cal65o$2e3b$1 digitaldaemon.com>, clayasaurus says...hey, right now i'm using a function like this to set a dynamic array's properties int[] array; set3array(array,1,2,3); void set3array(inout ALfloat[] array, float x, float y, float z) { array.length = 3; array[0] = x; array[1] = y; array[2] = z; } is there a better way to set array values than this?
Jun 14 2004
clayasaurus wrote:it is just so much nicer to be able to set the contents of an array in one line. I like the C way: array[] = {1,2,3}; is there a good reason why D doesn't have this?Although I haven't heard anything from Walter, I think this is just one of those things on his todo list. The D form would be: int array[] = [1,2,3]; Note that you can already do: const int array [] = [1,4,5]; -- -Anderson: http://badmama.com.au/~anderson/
Jun 15 2004
J Anderson wrote: <snip>int array[] = [1,2,3]; Note that you can already do: const int array [] = [1,4,5];Or static int array[] = [1, 4, 5]; But yes, as said before, it ought to work generally. http://www.digitalmars.com/drn-bin/wwwnews?D/26695 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 15 2004
"Stewart Gordon" <smjg_1998 yahoo.com> wrote in message news:camj35$1hod$1 digitaldaemon.com...J Anderson wrote: <snip>But this isn't good when you don't want a const array. I often wanted to write int[] array = [1,2,x2-x1,y2-y1]; Especially useful it would be for multidimensional arrays.int array[] = [1,2,3]; Note that you can already do: const int array [] = [1,4,5];Or static int array[] = [1, 4, 5]; But yes, as said before, it ought to work generally.http://www.digitalmars.com/drn-bin/wwwnews?D/26695 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 15 2004
Ivan Senji wrote:"Stewart Gordon" <smjg_1998 yahoo.com> wrote in message news:camj35$1hod$1 digitaldaemon.com...<snip><snip> I suppose "generally" would include this just 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.But yes, as said before, it ought to work generally.But this isn't good when you don't want a const array. I often wanted to write int[] array = [1,2,x2-x1,y2-y1];
Jun 15 2004