Re: Calculating/Averaging over a struct value

2012-03-21 Thread Jesse Phillips
On Wednesday, 21 March 2012 at 20:13:37 UTC, Jesse Phillips wrote: Note, I commented out reduce as it uses the array type instead of the calculation type. I think I'll file than as a bug. Also the reduce version would not give you a double back even if it did work, need a cast in there. Neve

Re: Calculating/Averaging over a struct value

2012-03-21 Thread Jesse Phillips
On Wednesday, 21 March 2012 at 17:02:05 UTC, Brian Brady wrote: As per the commented section, I want to be able to dynamically figure out, which member of the struct to average across, for all the structs in the array. Timon has given you an good example to get D to generate some code for yo

Re: Calculating/Averaging over a struct value

2012-03-21 Thread Brian Brady
Thanks for the replies. Timons reply answers my question ... now I just have to figure out how :P

Re: Calculating/Averaging over a struct value

2012-03-21 Thread bearophile
David Nadlinger: I don't think this will ever be supported (without using opDispatch) – para is a runtime value here… David Right, right, sorry, I meant a compile time argument. And even that, it's not clear what arr[].foo means. Maybe a lazy Range of that field, that is a lazy column. B

Re: Calculating/Averaging over a struct value

2012-03-21 Thread David Nadlinger
On Wednesday, 21 March 2012 at 18:11:11 UTC, bearophile wrote: Brian Brady: // but if I write x[].para if throws an error This is a quite natural syntax, and I think it's handy, but it's not supported yet. I don't think this will ever be supported (without using opDispatch) – para is a ru

Re: Calculating/Averaging over a struct value

2012-03-21 Thread bearophile
Brian Brady: // but if I write x[].para if throws an error This is a quite natural syntax, and I think it's handy, but it's not supported yet. Bye, bearophile

Re: Calculating/Averaging over a struct value

2012-03-21 Thread Timon Gehr
#! /usr/bin/rdmd import std.array; import std.csv; import std.stdio; import std.string; struct Data{ string Date; double d1; double d2; int i4; } double average(Data[] x, string para){ double result = 0.0; theswitch:switch(strip(para)){ foreach(member;__trait

Calculating/Averaging over a struct value

2012-03-21 Thread Brian Brady
All This might be relatively trivial so please point me at documentation to read if it is. I am creating an array of Structs(is this the best thing to do) as per the example below. #! /usr/bin/rdmd import std.array; import std.csv; import std.stdio; import std.string; struct Data { string Dat