Thread overview
Crazy stuff
Apr 27, 2008
Tower Ty
Apr 27, 2008
Simen Kjaeraas
Apr 27, 2008
Tower Ty
Apr 27, 2008
Simen Kjaeraas
Apr 27, 2008
Tower Ty
Apr 27, 2008
Bill Baxter
April 27, 2008
I suppose I'm getting tired but this array stuff is just so bloody non-intuiitive

I'm copying an array  of strings into another array of arrays of strings
char[][] array1
array1 has in it [ 1, 12/12/06, 0123456, Hubert, 340, 1240.00, 0.00 ]
and I want to accumulate it in ,
char[][][] array2
as a line in array2. Array1's contents will change on the next pass of the loop and I increase x by 1 and want to store it then in array2line2
So I try
array2[x]=array1;
or
array2[x]=array1[0..6]
or
array2[x]=array1[]
or Jesus I'm buggered if I know what to try next ,it could be anything

array2[x]=array1.dup don't work either
April 27, 2008
On Sun, 27 Apr 2008 14:58:12 +0200, Tower Ty <tytower@hotmail.com.au> wrote:

> I suppose I'm getting tired but this array stuff is just so bloody non-intuiitive
>
> I'm copying an array  of strings into another array of arrays of strings
> char[][] array1
> array1 has in it [ 1, 12/12/06, 0123456, Hubert, 340, 1240.00, 0.00 ]
> and I want to accumulate it in ,
> char[][][] array2
> as a line in array2. Array1's contents will change on the next pass of the loop and I increase x by 1 and want to store it then in array2line2
> So I try
> array2[x]=array1;
> or
> array2[x]=array1[0..6]
> or
> array2[x]=array1[]
> or Jesus I'm buggered if I know what to try next ,it could be anything
>
> array2[x]=array1.dup don't work either

This works on my confuser (DMD 2.013, DMD 1.029):

  string[] a = ["Hello", "World"];
  string[][] b;

  b ~= a.dup;

  a[0] = "HAI";
  a[1] = "WURLD!1";

  b ~= a.dup;

  writefln(b); // prints [[Hello,World],[HAI,WORLD!!!1]]


Without the .dups, output is [[HAI,WORLD!!!1],[HAI,WORLD!!!1]].

-- Simen
April 27, 2008
Simen Kjaeraas Wrote:

> On Sun, 27 Apr 2008 14:58:12 +0200, Tower Ty <tytower@hotmail.com.au> wrote:
> 
> > I suppose I'm getting tired but this array stuff is just so bloody non-intuiitive
> >
> > I'm copying an array  of strings into another array of arrays of strings
> > char[][] array1
> > array1 has in it [ 1, 12/12/06, 0123456, Hubert, 340, 1240.00, 0.00 ]
> > and I want to accumulate it in ,
> > char[][][] array2
> > as a line in array2. Array1's contents will change on the next pass of
> > the loop and I increase x by 1 and want to store it then in array2line2
> > So I try
> > array2[x]=array1;
> > or
> > array2[x]=array1[0..6]
> > or
> > array2[x]=array1[]
> > or Jesus I'm buggered if I know what to try next ,it could be anything
> >
> > array2[x]=array1.dup don't work either
> 
> This works on my confuser (DMD 2.013, DMD 1.029):
> 
>    string[] a = ["Hello", "World"];
>    string[][] b;
> 
>    b ~= a.dup;
> 
>    a[0] = "HAI";
>    a[1] = "WURLD!1";
> 
>    b ~= a.dup;
> 
>    writefln(b); // prints [[Hello,World],[HAI,WORLD!!!1]]
> 
> 
> Without the .dups, output is [[HAI,WORLD!!!1],[HAI,WORLD!!!1]].
> 
> -- Simen

Thanks -now to stick the hair back. Would never have thought of approaching it with append . Logically I just want to put it in a firm place with a defined index address.

Does not seem to be covered in the Tango book either.

So can you explain how you are using " string".
What are you importing to be able to use string?

April 27, 2008
Tower Ty <tytower@hotmail.com.au> wrote:

> Thanks -now to stick the hair back. Would never have thought of approaching it with append . Logically I just want to put it in a firm place with a defined index address.
>
> Does not seem to be covered in the Tango book either.

This works just as well:

  string[] a = ["Hello", "World"];
  string[][] b;

  b.length = 2;

  b[0] = a.dup;

  a[0] = "HAI";
  a[1] = "WURLD!1";

  b[1] = a.dup;

  writefln(b); // prints [[Hello,World],[HAI,WORLD!!!1]]


Now, without the b.length = 2;, you'll get an array bounds error, of course.

> So can you explain how you are using " string".
> What are you importing to be able to use string?

I'm just importing std.stdio. I think string is a compiler-defined alias, but I
can't say whence I got the idea.

-- Simen
April 27, 2008
Simen Kjaeraas Wrote:

> Tower Ty <tytower@hotmail.com.au> wrote:
> 
> > Thanks -now to stick the hair back. Would never have thought of approaching it with append . Logically I just want to put it in a firm place with a defined index address.
> >
> > Does not seem to be covered in the Tango book either.
> 
> This works just as well:
> 
>    string[] a = ["Hello", "World"];
>    string[][] b;
> 
>    b.length = 2;
> 
>    b[0] = a.dup;
> 
>    a[0] = "HAI";
>    a[1] = "WURLD!1";
> 
>    b[1] = a.dup;
> 
>    writefln(b); // prints [[Hello,World],[HAI,WORLD!!!1]]
> 
> 
> Now, without the b.length = 2;, you'll get an array bounds error, of course.
> 
> > So can you explain how you are using " string".
> > What are you importing to be able to use string?
> 
> I'm just importing std.stdio. I think string is a compiler-defined alias,
> but I
> can't say whence I got the idea.
> 
> -- Simen
Goodo I'll give that a try -thanks again.

As an aside I find that with Simens help in the above I can move forward but another problem raises its head with this array business

I am accumulating lines from a text file in my  char[][][] array. It writes the first seven lines of an eight line file OK but on the last line it writes the last line in the correct place but also corrupts the first lines data?

Here is an output example printed after each addition

[ 1, 12/12/06, 0123456, Hermans Haystack, 340, 1240.00, 0.00 ]

[ 1, 12/12/06, 0123456, Hermans Haystack, 340, 1240.00, 0.00, 2, 12/12/06, 0123457, Hermans Hoystack, 330, 0.00, 1075.00 ]

[ 1, 12/12/06, 0123456, Hermans Haystack, 340, 1240.00, 0.00, 2, 12/12/06, 0123457, Hermans Hoystack, 330, 0.00, 1075.00, 3, 12/12/06, 0123458, Hermans Hatstuck, 320, 670.00, 0.00 ]

[ 1, 12/12/06, 0123456, Hermans Haystack, 340, 1240.00, 0.00, 2, 12/12/06, 0123457, Hermans Hoystack, 330, 0.00, 1075.00, 3, 12/12/06, 0123458, Hermans Hatstuck, 320, 670.00, 0.00, 4, 12/12/06, 0123459, Hermans Hamstack the local Pig Farm and producer, 310, 315.00, 0.00 ]

[ 1, 12/12/06, 0123456, Hermans Haystack, 340, 1240.00, 0.00, 2, 12/12/06, 0123457, Hermans Hoystack, 330, 0.00, 1075.00, 3, 12/12/06, 0123458, Hermans Hatstuck, 320, 670.00, 0.00, 4, 12/12/06, 0123459, Hermans Hamstack the local Pig Farm and producer, 310, 315.00, 0.00, 5, 12/12/06, 0123460, Hermans Halstack, 300, 96.00, 0.00 ]

[ 1, 12/12/06, 0123456, Hermans Haystack, 340, 1240.00, 0.00, 2, 12/12/06, 0123457, Hermans Hoystack, 330, 0.00, 1075.00, 3, 12/12/06, 0123458, Hermans Hatstuck, 320, 670.00, 0.00, 4, 12/12/06, 0123459, Hermans Hamstack the local Pig Farm and producer, 310, 315.00, 0.00, 5, 12/12/06, 0123460, Hermans Halstack, 300, 96.00, 0.00, 6, 12/12/06, 0123461, Hermans Heystack, 290, 1841.00, 0.00 ]

[ 1, 12/12/06, 0123456, Hermans Haystack, 340, 1240.00, 0.00, 2, 12/12/06, 0123457, Hermans Hoystack, 330, 0.00, 1075.00, 3, 12/12/06, 0123458, Hermans Hatstuck, 320, 670.00, 0.00, 4, 12/12/06, 0123459, Hermans Hamstack the local Pig Farm and producer, 310, 315.00, 0.00, 5, 12/12/06, 0123460, Hermans Halstack, 300, 96.00, 0.00, 6, 12/12/06, 0123461, Hermans Heystack, 290, 1841.00, 0.00, 7, 14/12/08, 234999, Hermans Huystack, 311, 234.00, 0.00 ]

[ 8, 15/12/08, 235000,, ermans Heystuck,, 20,, 0.00,0., 0.00, 2, 12/12/06, 0123457, Hermans Hoystack, 330, 0.00, 1075.00, 3, 12/12/06, 0123458, Hermans Hatstuck, 320, 670.00, 0.00, 4, 12/12/06, 0123459, Hermans Hamstack the local Pig Farm and producer, 310, 315.00, 0.00, 5, 12/12/06, 0123460, Hermans Halstack, 300, 96.00, 0.00, 6, 12/12/06, 0123461, Hermans Heystack, 290, 1841.00, 0.00, 7, 14/12/08, 234999, Hermans Huystack, 311, 234.00, 0.00, 8, 15/12/08, 235000, Hermans Heystuck, 220, 60.00, 0.00 ]


The data is fine unyil the last line
I produce the data with

foreach (line; new LineIterator!(char) (new FileConduit ("data.csv"))){
      TableItem item = new TableItem (table, DWT.RIGHT);
      fields = TextUtil.delimit(line,",");

Anyone have any idea why the data is corrupted?
April 27, 2008
"Simen Kjaeraas" <simen.kjaras@gmail.com> wrote in message news:op.uaaga9ht1hx7vj@spill04.lan...

I'm just importing std.stdio. I think string is a compiler-defined alias,
but I
can't say whence I got the idea.

------------------------

string/wstring/dstring are defined in object.d, which is implicitly imported from every module.  So it might as well be defined by the compiler.  In D1, they alias to char[], wchar[], and dchar[]; in D2, invariant(char)[], invariant(wchar)[], and invariant(dchar)[].


April 27, 2008
Jarrett Billingsley wrote:
> "Simen Kjaeraas" <simen.kjaras@gmail.com> wrote in message news:op.uaaga9ht1hx7vj@spill04.lan...
> 
> I'm just importing std.stdio. I think string is a compiler-defined alias,
> but I
> can't say whence I got the idea.
> 
> ------------------------
> 
> string/wstring/dstring are defined in object.d, which is implicitly imported from every module.  So it might as well be defined by the compiler.  In D1, they alias to char[], wchar[], and dchar[]; in D2, invariant(char)[], invariant(wchar)[], and invariant(dchar)[]. 

... in Phobos.  But not in Tango.  Unless it changed in the release that came out yesterday or so.

--bb
April 29, 2008
"Tower Ty" wrote
> Goodo I'll give that a try -thanks again.
>
> As an aside I find that with Simens help in the above I can move forward but another problem raises its head with this array business
>
> I am accumulating lines from a text file in my  char[][][] array. It writes the first seven lines of an eight line file OK but on the last line it writes the last line in the correct place but also corrupts the first lines data?
>
> ...
>
> The data is fine unyil the last line
> I produce the data with
>
> foreach (line; new LineIterator!(char) (new FileConduit ("data.csv"))){
>      TableItem item = new TableItem (table, DWT.RIGHT);
>      fields = TextUtil.delimit(line,",");
>
> Anyone have any idea why the data is corrupted?

Yes, LineIterator re-uses the same data buffer while reading the file for efficiency.  If you want to save the data that LineIterator gives you, use

fields = TextUtil.delmit(line.dup,",");

What this does is make a copy of the line, then split that up.  When the LineIterator re-uses the buffer, it won't affect your copies.

And Tango does not use 'string' as a keyword, that is Phobos only.

Hope that helps.

-Steve