digitalmars.D.learn - Question about mutable arrays
- A Bothe (9/9) Nov 19 2009 Hey guys,
- Ellery Newcomer (3/17) Nov 19 2009 a[0] = "Test".dup;
- Phil Deets (6/16) Nov 19 2009 Does a still have length 0. You may be getting an array out of bounds
- Ali Cehreli (6/12) Nov 19 2009 I like to see it a "slice." Even if we go with "dynamic array," I see it...
- A Bothe (14/14) Nov 20 2009 These lines were just a basic idea...of course I have to fill the array....
- Steven Schveighoffer (11/27) Nov 23 2009 First, it looks like you are assuming you can just assign an element of ...
Hey guys, I've found a problem that occurred since DMD 2.034: When I've created a dynamic array like string[] a; and I want to assign something via the index of this array a[0]="Test"; DMD says the array isn't mutable...even if these are normal types like int or char. Does anybody knows how to solve this problem? Thank in advance
Nov 19 2009
A Bothe wrote:Hey guys, I've found a problem that occurred since DMD 2.034: When I've created a dynamic array like string[] a; and I want to assign something via the index of this array a[0]="Test"; DMD says the array isn't mutable...even if these are normal types like int or char. Does anybody knows how to solve this problem? Thank in advancea[0] = "Test".dup; ?
Nov 19 2009
On Thu, 19 Nov 2009 09:16:16 -0500, A Bothe <info alexanderbothe.com> wrote:Hey guys, I've found a problem that occurred since DMD 2.034: When I've created a dynamic array like string[] a; and I want to assign something via the index of this array a[0]="Test"; DMD says the array isn't mutable...even if these are normal types like int or char. Does anybody knows how to solve this problem? Thank in advanceDoes a still have length 0. You may be getting an array out of bounds error with a weird error message. -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Nov 19 2009
A Bothe Wrote:I've found a problem that occurred since DMD 2.034:I am testing it with 2.036.When I've created a dynamic array like string[] a;I like to see it a "slice." Even if we go with "dynamic array," I see it as an empty dynamic array.and I want to assign something via the index of this array a[0]="Test";I would expect it to be illegal to access a[0], because a is empty.DMD says the array isn't mutable...2.036 says "Error: null dereference in function _Dmain" and it matches my expectation above. Ali
Nov 19 2009
These lines were just a basic idea...of course I have to fill the array... string[] a=new string[2]; a[0]="A"; a[1]="B"; my idea was to create a list class to store something in it... class List(T) { T[] arr; // ctors and such void opIndexAssign(T e,int i) { arr[i]=e; // And here it throws the exception that arr is not mutable... } }
Nov 20 2009
On Fri, 20 Nov 2009 09:42:55 -0500, A Bothe <info alexanderbothe.com> wrote:These lines were just a basic idea...of course I have to fill the array... string[] a=new string[2]; a[0]="A"; a[1]="B"; my idea was to create a list class to store something in it... class List(T) { T[] arr; // ctors and such void opIndexAssign(T e,int i) { arr[i]=e; // And here it throws the exception that arr is not mutable... } }First, it looks like you are assuming you can just assign an element of an array without ensuring the array is large enough to hold it. This works in some dynamic languages but not D. Second, if you have done that properly, this should work if T is string, because although string is not fully "mutable", it is rebindable. Can you post a full code example, and the exact error message you get? It's hard to guess what problem you are running into. You don't need to post full code, just enough to make the error occur. -Steve
Nov 23 2009