Template recursion error on table struct

data pulverizer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Mar 26 00:02:20 PDT 2016


On Saturday, 26 March 2016 at 06:28:42 UTC, Ali Çehreli wrote:
> WARNING: Do not try to compile this code. Your computer may be 
> unresponsive for a while. :)
>
> On 03/25/2016 02:54 PM, data pulverizer wrote:
> > I am attempting to create a table struct with generic column
> types using
> > templates.
>
> However, the template arguments are not types; rather, aliases.
>
> > template ColumnTable(T...){
> >      struct ColumnTable{
> >      private:
> >          typeof(T) data;
> >          string[] names;
> >          struct Range{
> >              size_t begin;
> >              size_t end;
> >          }
> >          // This function is the source of the issue
> >      auto subTable(Range rowRange, Range columnRange)(){
> >          auto new_data = data[columnRange.begin ..
> columnRange.end];
> >          auto output = ColumnTable!(new_data)(new_data); //
> This is the
> > problem
>
> new_data is a local variable. So, this instantiation of 
> ColumnTable is with that symbol.
>
> > void main(){
> >      string[] names = ["tariq", "sharma", "peter", "rakel"];
> >      double[] salary = [44.5, 32.2, 40.1, 28.1];
> >      int[] age = [24, 20, 22, 25, 19];
> >      writeln(ColumnTable!(names, salary, age)(names, salary,
> age));
> > }
>
> Likewise, that instantiation of ColumnTable is with the symbols 
> 'names', 'salary', and 'age'. Is that what you want? Or do you 
> want to instantiate with their types? Can you explain some more 
> what you are trying to do.
>
> Ali

I am trying to build a table similar to R's dataframe but with 
unbounded data types. I am hoping that D's flexible template 
programming methods will allow table-like class or struct to be 
constructed with "naked" types i.e. unwrapped with variant. The 
ColumnTable object consists of vector columns that are bound 
together in a tuple - the data member and accessed in a similar 
way to your matrix example. The table will have column names and 
should be accessible by:

table[0..4, "colname"]
table[0..4, ["colname_1", "colname_2", "colname_3"]]
table[0..$, 0..4]

and should be able to be subsetted and inserted into by another 
table

table_1[0..4, 3..4] = table_2
table_1[0..4, ["colname_1", "colname_2"]] = table_2

and columns could be added or overwritten

table[0..$, 0] = someVector
table.columnBind(someVector)

column bind two table together ...

auto new_table = ColumnTable(table_1, table_2)
auto new_table = ColumnTable(table_1, someVector)

row bind two table having the same column characteristics

auto new_table = rbind(table_1, table_2)

Then perhaps do something similar for row-based tables.


More information about the Digitalmars-d-learn mailing list