Re: Should be easy
> Ever heard of recursion? > > Why don't you simply handle all types recursively? Why do you need this > "array depth" stuff? Most probably because I tackle my parsing problem sub-optimally. This is how I do it: load file into char[][] create: int[][][] arr; call: ddata.get( (in) file, (in) 'array1', (ref) arr); find row starting with 'int[][][] array1'. parse char by char from there every time the end of a value is found convert the slice to the correct type and put it in the corresponding arr index. return;
Re: Should be easy
Ever heard of recursion? Why don't you simply handle all types recursively? Why do you need this "array depth" stuff?
Re: [OT] quoting text
Hello Steven, On Fri, 12 Jun 2009 19:40:02 -0400, Denis Koroskin <2kor...@gmail.com> wrote: Just don't quote. Why include quote, if there is nothing under it? Why is it that some email clients start you out at the top of the quoted messages, and some clients go below? I guess it depends on your style. If you respond to the entire message, then putting at the top makes sense, because then you can read the response quickly, and read the history below if you want. But if you want to respond point-by-point, then going below makes sense. You can respond to each point, then have your main point at the bottomm of the message. I think that bit is the main reason. If you are not referencing something, then delete it from the quote. If you are referencing it, put your stuff below, sort of like a caption.
Re: [OT] quoting text
> I guess it depends on your style. If you respond to the entire message, > then putting at the top makes sense, because then you can read the > response quickly, and read the history below if you want. I also switch my way of reply on the type of the reply and often find it strange people quote the whole post only to reply something general. > > But if you want to respond point-by-point, then going below makes sense. > You can respond to each point, then have your main point at the bottomm of > the message. Who would do that! > > My email clients always put quoted text below. However, my news client > always quotes above. > > Someone should do a study... Don't tell me nobody did that already . .
[OT] quoting text
On Fri, 12 Jun 2009 19:40:02 -0400, Denis Koroskin <2kor...@gmail.com> wrote: Just don't quote. Why include quote, if there is nothing under it? Why is it that some email clients start you out at the top of the quoted messages, and some clients go below? I guess it depends on your style. If you respond to the entire message, then putting at the top makes sense, because then you can read the response quickly, and read the history below if you want. But if you want to respond point-by-point, then going below makes sense. You can respond to each point, then have your main point at the bottomm of the message. My email clients always put quoted text below. However, my news client always quotes above. Someone should do a study... -Steve
Re: Should be easy
> Saaa wrote: >> I can't figure out how to create the IndexArray function, >> it should work on arrays of any depth > > BaseType!(TArray) index(TArray : TArray[])(TArray array, int[] indices...) > { > return index(array[indices[0]], indices[1..$]); > } > > TElement index(TElement)(TElement element, int[] ignored...) > { > return element; > } > > This uses template specialization to handle arrays differently than > non-arrays (that's what the "TArray : TArray[]" business means). It uses > the BaseType template worked out in one of your previous threads. It's > close enough to being the simplest thing that could work that I wouldn't > bother looking for anything simpler. I really like templates :D I actually tried something like this, but I couldn't get it to compile. My try misses quit a few things I see void IndexArray(T : T[], U)(T array, U index) { IndexArray( array[index[0]][], index[1..$]); } void IndexArray(T : int, U)(T array, U index) { array[index[0]] = -7;//test } I did get it to compile at one time, but didn't know how to use it, like your code.. index( array, index2); //compiles and all, but how do I set the value? index( array, index2) = -1; // doesn't work Also, why the ... ?
Re: Should be easy
On Sat, 13 Jun 2009 03:37:59 +0400, Saaa wrote: IndexArray should take an array of integers as well. The int[] foo... syntax is implicit "convert to array" anyway. I think I'll go with Christophers code, hope you don't mind :) Also, please bottom-post. It's the convention. :) Why is that? scroll scroll I probably use a retarded newsreader :D Just don't quote. Why include quote, if there is nothing under it?
Re: Should be easy
> > IndexArray should take an array of integers as well. The int[] foo... > syntax is implicit "convert to array" anyway. I think I'll go with Christophers code, hope you don't mind :) > > Also, please bottom-post. It's the convention. > > :) Why is that? scroll scroll I probably use a retarded newsreader :D
Re: Should be easy
Saaa wrote: I can't figure out how to create the IndexArray function, it should work on arrays of any depth BaseType!(TArray) index(TArray : TArray[])(TArray array, int[] indices...) { return index(array[indices[0]], indices[1..$]); } TElement index(TElement)(TElement element, int[] ignored...) { return element; } This uses template specialization to handle arrays differently than non-arrays (that's what the "TArray : TArray[]" business means). It uses the BaseType template worked out in one of your previous threads. It's close enough to being the simplest thing that could work that I wouldn't bother looking for anything simpler.
Re: Should be easy
Saaa wrote: > Thanks! > I thought about the idea of just creating the code and mix it in, but now I > can see why I failed at that: Your code is kind of read-only to me, for now, > because I need to change it a bit to accept an array instead of seperat > indices. > > Wouldn't it be nice if it worked like this: > int[] index = (1,2,3); > array(index) = -1; > >> Here's one. >> >> module test144; >> >> import std.stdio, std.metastrings; >> >> struct PointerAssign(T) { >> T* ptr; >> T opAssign(T t) { *ptr = t; return t; } >> static PointerAssign opCall(T* p) { PointerAssign res; res.ptr = p; >> return res; } >> } >> >> template isArray(T: T[]) { const bool isArray = true; } >> template isArray(T) { const bool isArray = false; } >> >> template Init(T) { const T Init; } >> template ElemType(T) { alias typeof(Init!(T)[0]) ElemType; } >> >> template BaseType(T) { >> static if (isArray!(T)) alias BaseType!(ElemType!(T)) BaseType; >> else alias T BaseType; >> } >> >> template Depth(T) { >> static if (isArray!(T)) const int Depth = 1 + Depth!(ElemType!(T)); >> else const int Depth = 0; >> } >> >> string ctToString(int i) { >> if (!i) return "0"; >> string res; >> while (i) { >>res = "0123456789"[i%10] ~ res; >>i /= 10; >> } >> return res; >> } >> >> string index(int len) { >> string res; >> for (int i = 0; i < len; ++i) >>res ~= "[indices["~ctToString(i)~"]] "; >> return res; >> } >> >> PointerAssign!(BaseType!(T)) IndexArray(T)(T array, int[] indices...) { >> return PointerAssign!(BaseType!(T)) (mixin("&array"~index(Depth!(T; >> } >> >> void main() { >> int[][][] array; >> array.length = 10; >> array[1].length = 3; >> array[1][2].length = 4; >> array[1][2][1] = 99; >> writefln(array); >> IndexArray(array, 1, 2, 3) = -1; >> writefln(array); >> } > > IndexArray should take an array of integers as well. The int[] foo... syntax is implicit "convert to array" anyway. Also, please bottom-post. It's the convention. :)
Re: Should be easy
Thanks! I thought about the idea of just creating the code and mix it in, but now I can see why I failed at that: Your code is kind of read-only to me, for now, because I need to change it a bit to accept an array instead of seperat indices. Wouldn't it be nice if it worked like this: int[] index = (1,2,3); array(index) = -1; > > Here's one. > > module test144; > > import std.stdio, std.metastrings; > > struct PointerAssign(T) { > T* ptr; > T opAssign(T t) { *ptr = t; return t; } > static PointerAssign opCall(T* p) { PointerAssign res; res.ptr = p; > return res; } > } > > template isArray(T: T[]) { const bool isArray = true; } > template isArray(T) { const bool isArray = false; } > > template Init(T) { const T Init; } > template ElemType(T) { alias typeof(Init!(T)[0]) ElemType; } > > template BaseType(T) { > static if (isArray!(T)) alias BaseType!(ElemType!(T)) BaseType; > else alias T BaseType; > } > > template Depth(T) { > static if (isArray!(T)) const int Depth = 1 + Depth!(ElemType!(T)); > else const int Depth = 0; > } > > string ctToString(int i) { > if (!i) return "0"; > string res; > while (i) { >res = "0123456789"[i%10] ~ res; >i /= 10; > } > return res; > } > > string index(int len) { > string res; > for (int i = 0; i < len; ++i) >res ~= "[indices["~ctToString(i)~"]] "; > return res; > } > > PointerAssign!(BaseType!(T)) IndexArray(T)(T array, int[] indices...) { > return PointerAssign!(BaseType!(T)) (mixin("&array"~index(Depth!(T; > } > > void main() { > int[][][] array; > array.length = 10; > array[1].length = 3; > array[1][2].length = 4; > array[1][2][1] = 99; > writefln(array); > IndexArray(array, 1, 2, 3) = -1; > writefln(array); > }
Re: tuples
On Fri, Jun 12, 2009 at 11:00 AM, Jarrett Billingsley wrote: > On Fri, Jun 12, 2009 at 12:10 AM, Ellery > Newcomer wrote: >> what is up with this code? >> >> auto t = tuple(1,'a',3.333,false); >> pragma(msg,typeof(t.tupleof[2 .. $]).stringof); >> >> spits out >> >> (double, bool, int, char, double, bool) >> > > It has to do with the way Tuple is implemented in std.typecons: > > union > { > Types field; > mixin(tupleFields!(0, T)); > } > > "field" is of type (double, bool, int, char), and the mixin defines > something like "struct { double _0; bool _1; int _2; char _3; }". > Since it's a union, the field member overlaps with the anonymous > struct, just giving you two different ways of accessing the same > member: t.field[0] or t._0. > > When DMD does the tupleof, it puts all the union members in the tuple, > giving you what looks like a duplicated type list. > > You can instead use: > > pragma(msg,typeof(t.field[$ - 2 .. $]).stringof); Er, pragma(msg,typeof(t.field[2 .. $]).stringof);
Re: tuples
On Fri, Jun 12, 2009 at 12:10 AM, Ellery Newcomer wrote: > what is up with this code? > > auto t = tuple(1,'a',3.333,false); > pragma(msg,typeof(t.tupleof[2 .. $]).stringof); > > spits out > > (double, bool, int, char, double, bool) > It has to do with the way Tuple is implemented in std.typecons: union { Types field; mixin(tupleFields!(0, T)); } "field" is of type (double, bool, int, char), and the mixin defines something like "struct { double _0; bool _1; int _2; char _3; }". Since it's a union, the field member overlaps with the anonymous struct, just giving you two different ways of accessing the same member: t.field[0] or t._0. When DMD does the tupleof, it puts all the union members in the tuple, giving you what looks like a duplicated type list. You can instead use: pragma(msg,typeof(t.field[$ - 2 .. $]).stringof);
Re: Should be easy
Saaa wrote: > I can't figure out how to create the IndexArray function, > it should work on arrays of any depth > > int[][][] array; //any depth > array.length=10; > array[1].length=3; > array[1][2].length=4; > array[1][2][1]=99; > > writefln(array); > //[[],[[],[],[0,99,0,0]],[],[],[],[],[],[],[],[]] > > int[3] index; //same length as depth > index[0]=1; > index[1]=2; > index[2]=3; > > IndexArray( array, index) = -1; > //equal to : > //array[ index[0] ][ index[1] ][ index[2] ] = -1; > > writefln(array); > //[[],[[],[],[0,99,0,-1]],[],[],[],[],[],[],[],[]] > > All suggestions are greatly appreciated ! > > > Here's one. module test144; import std.stdio, std.metastrings; struct PointerAssign(T) { T* ptr; T opAssign(T t) { *ptr = t; return t; } static PointerAssign opCall(T* p) { PointerAssign res; res.ptr = p; return res; } } template isArray(T: T[]) { const bool isArray = true; } template isArray(T) { const bool isArray = false; } template Init(T) { const T Init; } template ElemType(T) { alias typeof(Init!(T)[0]) ElemType; } template BaseType(T) { static if (isArray!(T)) alias BaseType!(ElemType!(T)) BaseType; else alias T BaseType; } template Depth(T) { static if (isArray!(T)) const int Depth = 1 + Depth!(ElemType!(T)); else const int Depth = 0; } string ctToString(int i) { if (!i) return "0"; string res; while (i) { res = "0123456789"[i%10] ~ res; i /= 10; } return res; } string index(int len) { string res; for (int i = 0; i < len; ++i) res ~= "[indices["~ctToString(i)~"]] "; return res; } PointerAssign!(BaseType!(T)) IndexArray(T)(T array, int[] indices...) { return PointerAssign!(BaseType!(T)) (mixin("&array"~index(Depth!(T; } void main() { int[][][] array; array.length = 10; array[1].length = 3; array[1][2].length = 4; array[1][2][1] = 99; writefln(array); IndexArray(array, 1, 2, 3) = -1; writefln(array); }
Re: Should be easy
Thanks. But my problem lays in supporting arrays of arbitrary depth. > For 2 dim array I like "auto a=new char[][](40,25);" so that > "a[39][24]='B';" 'B' is at the bottom right of the 2D array.
Re: Should be easy
For 2 dim array I like "auto a=new char[][](40,25);" so that "a[39][24]='B';" 'B' is at the bottom right of the 2D array.
Should be easy
I can't figure out how to create the IndexArray function, it should work on arrays of any depth int[][][] array; //any depth array.length=10; array[1].length=3; array[1][2].length=4; array[1][2][1]=99; writefln(array); //[[],[[],[],[0,99,0,0]],[],[],[],[],[],[],[],[]] int[3] index; //same length as depth index[0]=1; index[1]=2; index[2]=3; IndexArray( array, index) = -1; //equal to : //array[ index[0] ][ index[1] ][ index[2] ] = -1; writefln(array); //[[],[[],[],[0,99,0,-1]],[],[],[],[],[],[],[],[]] All suggestions are greatly appreciated !