Re: array initialization problem

2009-01-20 Thread Chris Nicholson-Sauls
Rainer Deyke wrote: Denis Koroskin wrote: Arrays in D are reference types. Besides, it's best to avoid hidden allocations. Arrays in D are reference types except when they're not. int[] a = [5]; int[] b = a; a[0] = 4; assert(b[0] == 4); a.length = 2; assert(b.length == 1); a[0] = 3; // Is b[0

Re: array initialization problem

2009-01-19 Thread Rainer Deyke
Denis Koroskin wrote: > Arrays in D are reference types. Besides, it's best to avoid hidden > allocations. Arrays in D are reference types except when they're not. int[] a = [5]; int[] b = a; a[0] = 4; assert(b[0] == 4); a.length = 2; assert(b.length == 1); a[0] = 3; // Is b[0] 3 or 4? -- Rain

Re: array initialization problem

2009-01-19 Thread Christopher Wright
Qian Xu wrote: Denis Koroskin wrote: ... For example, let's modify CSTR and see what happens: CSTR[0] = 'J'; // now it is "Jello" printing e.str and e2.str gives us the following output: Jello Jello ... Hi again, but there is one thing, I do not understand. CSTR is a constant. But with "C

Re: array initialization problem

2009-01-19 Thread Denis Koroskin
On Mon, 19 Jan 2009 12:21:59 +0300, Qian Xu wrote: Denis Koroskin wrote: ... For example, let's modify CSTR and see what happens: CSTR[0] = 'J'; // now it is "Jello" printing e.str and e2.str gives us the following output: Jello Jello ... Hi again, but there is one thing, I do not under

Re: array initialization problem

2009-01-19 Thread Qian Xu
Denis Koroskin wrote: > ... > > For example, let's modify CSTR and see what happens: > CSTR[0] = 'J'; // now it is "Jello" > > printing e.str and e2.str gives us the following output: > Jello > Jello > > ... Hi again, but there is one thing, I do not understand. CSTR is a constant. But with "

Re: array initialization problem

2009-01-18 Thread Qian Xu
Denis Koroskin wrote: 7 - e2.str = "world"; State: CLIST : ["333", "444"]; e : list = ["333", "444"]; str = "hello"; e2: list = ["333", "444"]; str = "world"; Hope it helps. Thanks for your nice answer. You made my day ;-) -- Xu, Qian (stanleyxu) http://stanleyxu2005.b

Re: array initialization problem

2009-01-16 Thread Denis Koroskin
On Sat, 17 Jan 2009 00:19:46 +0300, Qian Xu wrote: Hi All, I have accidentally written a buggy class. Briefly described as follows: 1. The class contains a list of string 2. The list of string is assigned to a constant in constructor 3. Try to change the value of the list 4. Create an

Re: array initialization problem

2009-01-16 Thread Jarrett Billingsley
On Fri, Jan 16, 2009 at 4:19 PM, Qian Xu wrote: > Can someone explain, why the values are different before they are inserted > into a list? The values are different _before you insert values into e2_. Try printing out the contents of e _after_ you put strings in e2, and you'll notice it now has