Error: variable i cannot be read at compile time
Vino
vino.bheeman at hotmail.com
Sat Jan 6 09:11:02 UTC 2018
On Saturday, 6 January 2018 at 06:47:33 UTC, Vino wrote:
> On Friday, 5 January 2018 at 18:00:34 UTC, thedeemon wrote:
>> On Friday, 5 January 2018 at 17:59:32 UTC, thedeemon wrote:
>>> Tuple!( staticMap!(Arr, ColumnTypes) ) res; // array of
>>> tuples
>>
>> Sorry, I meant tuple of arrays, of course.
>
> Hi Deemon,
>
> Thank you very much, I tested your code, initially the code
> did not produce the expected output, and found an issue in the
> the key line of code as below, after updating the output was as
> expected. Can you please let me know how to change the array
> from standard array to container array.
>
> auto ks = col.map!(v => col.countUntil(v)).array; // Your
> code(col.countUntil)
> auto ks = col.map!(v => vals.countUntil(v)).array; // Changed
> code(vals.countUntil)
>
> From,
> Vino.B
Hi Deemon,
Was able to convert 50% of the code to container array and facing
some issue
import std.algorithm: countUntil, joiner, sort, uniq, map;
import std.csv: csvReader;
import std.stdio: File, writeln;
import std.typecons: Tuple, tuple;
import std.meta: AliasSeq;
import std.container.array;
alias ColumnTypes = AliasSeq!(string, string, int);
alias Arr(T) = Array!T;
auto readData() {
auto file =
File("C:\\Users\\bheev1\\Desktop\\Current\\Script\\Others\\TColRead.csv", "r");
Arr!(Tuple!ColumnTypes) res;
foreach (record;
file.byLineCopy.joiner("\n").csvReader!(Tuple!ColumnTypes))
{ res.insertBack(record); }
return tuple(res[]); // replace this line with writeln(res[]);
gives the expected output
}
auto compress(T)(Array!T col) {
Arr!int ks; Array!T vals;
vals.insertBack(sort(col.dup[]).uniq);
ks.insertBack(col.map!(v => vals.countUntil(v)));
return tuple(vals, ks);
}
void main() {
auto columns = readData();
foreach(i, ColT; ColumnTypes) { //Facing some
issue at this point
auto vk = compress(columns[i]);
writeln(vk[0][], vk[1][]);
}
}
From,
Vino.B
More information about the Digitalmars-d-learn
mailing list