Re: Error: variable i cannot be read at compile time

2018-01-07 Thread Vino via Digitalmars-d-learn

On Monday, 8 January 2018 at 05:38:44 UTC, thedeemon wrote:

On Sunday, 7 January 2018 at 17:30:26 UTC, Vino wrote:

 I tried to manipulate the writeln's as below but the output 
is not as expected as it prints the data in row wise, where as 
we need it in column wise.


You've said before you need 6 different files, not some tables.
Also, after the "compression" data columns will have different 
length. How exactly do you want to combine them into a table?


Hi Deemon,

  The output required is like this,

(1) Read a table data form the csv file

John, America,23
John, India, 22
Astro, Canada, 21

2) Sort and remove the duplicates from each column by column

Take a copy of each column and sort and remove the duplicates 
(col.dup) and store the resultant data of each column in seprate 
files like below.


Column 1 ( Store the data to text Datafille1)
Astro
John

Column 2 ( Store the data to text Datafille2)
America
Canada
India

Column 3 ( Store the data to text Datafille3)
21
22
23

Using the function countUntil find the keys for each of the 
column and store the result of each column in another files.


Key for column to text Keyfille1
original column1[].map!(v => Sorted Column1[].countUntil(v)) );

Key for column to text Keyfille2
original column2[].map!(v => Sorted Column2[].countUntil(v)) );

Key for column to text Keyfille3
original column3[].map!(v => Sorted Column3[].countUntil(v)) );


From,
Vino.B







Re: Error: variable i cannot be read at compile time

2018-01-07 Thread thedeemon via Digitalmars-d-learn

On Sunday, 7 January 2018 at 17:30:26 UTC, Vino wrote:

 I tried to manipulate the writeln's as below but the output is 
not as expected as it prints the data in row wise, where as we 
need it in column wise.


You've said before you need 6 different files, not some tables.
Also, after the "compression" data columns will have different 
length. How exactly do you want to combine them into a table?


Re: Is old style compile-time foreach redundant?

2018-01-07 Thread Steven Schveighoffer via Digitalmars-d-learn

On 1/6/18 6:25 PM, Ali Çehreli wrote:
Is 'static foreach' sufficient for all needs or is there any value for 
regular foreach over compile-time sequences?


If you use continues or breaks, then you need to switch to gotos if 
using static foreach, as it does not support them directly.


-Steve


Re: Error: variable i cannot be read at compile time

2018-01-07 Thread Vino via Digitalmars-d-learn

On Sunday, 7 January 2018 at 17:23:20 UTC, thedeemon wrote:

On Sunday, 7 January 2018 at 12:59:10 UTC, Vino wrote:
 Just noticed that the output writes the data and key as 2 
values , but the requirnment is to write to six files, e.g


That's the part you can implement yourself. Just replace those 
writelns with writing to corresponding files.


HI Deemon,

 I tried to manipulate the writeln's as below but the output is 
not as expected as it prints the data in row wise, where as we 
need it in column wise.


writeln(vk[0][0]);

Baker
America
18

From,
Vino.B


Re: Error: variable i cannot be read at compile time

2018-01-07 Thread thedeemon via Digitalmars-d-learn

On Sunday, 7 January 2018 at 12:59:10 UTC, Vino wrote:
 Just noticed that the output writes the data and key as 2 
values , but the requirnment is to write to six files, e.g


That's the part you can implement yourself. Just replace those 
writelns with writing to corresponding files.


Column wise output

2018-01-07 Thread Vino via Digitalmars-d-learn

HI All,

  Request your help, in the below code the output from main 
(writeln(columns[0][])) function is like ["Miller", "John", 
"Millman", "Zsuwalski"] where as the writeln(col[0]) from the 
function master is as below, so how do i get the output same as 
in main from the function master.


CSV file content
Miller, America, 23
John, Africa, 42

Output from function master
Miller
America
23

alias ColumnTypes = AliasSeq!(string, string, int);

auto readData(string fName) {
auto uFile = File(fName, "r");
Tuple!( staticMap!(Array, ColumnTypes) ) res;
foreach (record; 
uFile.byLineCopy().joiner("\n").csvReader!(Tuple!ColumnTypes)) {

foreach(i, T; ColumnTypes) { res[i].insert(record[i]); }
}
return res;
}

auto master(T)(ref Array!T col) {
writeln(col[0]);  // The output2 is  Miller
  //  America
   //23
}


void main() {
auto fName = 
"C:\\Users\\bheev1\\Desktop\\Current\\Script\\Others\\TColRead.csv";

auto columns = readData(fName);
writeln(columns[0][]);  // The output1 is ["Miller", "John"]
foreach(i, ColT; ColumnTypes) {
dictcompress(columns[i]);
}
}

From,
Vino.B


Re: Finding ElementType

2018-01-07 Thread Bastiaan Veelo via Digitalmars-d-learn

On Sunday, 7 January 2018 at 13:50:23 UTC, Adam D. Ruppe wrote:

On Sunday, 7 January 2018 at 12:40:22 UTC, Bastiaan Veelo wrote:
1) Should we have a reference in the docs for std.traits to 
std.range.primitive : ElementType?


wouldn't hurt i guess

2) Should phobos contain a version without the special narrow 
string behavior?


see ElementEncodingType
http://dpldocs.info/experimental-docs/std.range.primitives.ElementEncodingType.html

3) Are there other differences between my version and the 
phobos version?


The Phobos one works on any range, not just built-in arrays. It 
also returns an answer (void) if you pass it something that has 
no element type, whereas yours would be a compile error.


Thanks.


Re: Finding ElementType

2018-01-07 Thread Adam D. Ruppe via Digitalmars-d-learn

On Sunday, 7 January 2018 at 12:40:22 UTC, Bastiaan Veelo wrote:
1) Should we have a reference in the docs for std.traits to 
std.range.primitive : ElementType?


wouldn't hurt i guess

2) Should phobos contain a version without the special narrow 
string behavior?


see ElementEncodingType
http://dpldocs.info/experimental-docs/std.range.primitives.ElementEncodingType.html

3) Are there other differences between my version and the 
phobos version?


The Phobos one works on any range, not just built-in arrays. It 
also returns an answer (void) if you pass it something that has 
no element type, whereas yours would be a compile error.


Re: Help optimizing UnCompress for gzipped files

2018-01-07 Thread Steven Schveighoffer via Digitalmars-d-learn

On 1/6/18 11:14 AM, Christian Köstlin wrote:

On 05.01.18 23:04, Steven Schveighoffer wrote:

One thing to try, you preallocate the ENTIRE buffer. This only works if
you know how many bytes it will decompress to (not always possible), but
it will take the allocator out of the equation completely. And it's
probably going to be the most efficient method (you aren't leaving
behind smaller unused blocks when you realloc). If for some reason we
can't beat/tie the C version doing that, then something else is going on.

yes ... this is something i forgot to try out ... will do now :)
mhh .. interesting numbers ... c is even faster, my d lowlevel solution
is also a little bit faster, but much slower than the no copy version
(funnily, no copy is the wrong name, it just overwrites all the data in
a small buffer).


Not from what I'm reading, the C solution is about the same (257 vs. 
261). Not sure if you have averaged these numbers, especially on a real 
computer that might be doing other things.


Note: I would expect it to be a tiny bit faster, but not monumentally 
faster. From my testing with the reallocation, it only reallocates a 
large quantity of data once.


However, the D solution should be much faster. Part of the issue is that 
you still aren't low-level enough :)


Instead of allocating the ubyte array with this line:

ubyte[] buffer = new ubyte[200*1024*1024];

Try this instead:

// from std.array
auto buffer = uninitializedArray!(ubyte[], 200*1024*1024);

The difference is that the first one will have the runtime 0-initialize 
all the data.



one question about iopipe. is it possible to transform the elements in
the pipe as well ... e.g. away from a buffer of bytes to json objects?


Yes! I am working on doing just that, but haven't had a chance to update 
the toy project I wrote: https://github.com/schveiguy/jsoniopipe


I was planning actually on having an iopipe of JsonItem, which would 
work just like a normal buffer, but reference the ubyte buffer underneath.


Eventually, the final product should have a range of JsonValue, which 
you would recurse into in order to parse its children. All of it will be 
lazy, and stream-based, so you don't have to load the whole file if it's 
huge.


Note, you can't have an iopipe of JsonValue, because it's a recursive 
format. JsonItems are just individual defined tokens, so they can be linear.


-Steve


Re: Error: variable i cannot be read at compile time

2018-01-07 Thread Vino via Digitalmars-d-learn

On Sunday, 7 January 2018 at 12:09:32 UTC, Vino wrote:

On Saturday, 6 January 2018 at 15:32:14 UTC, thedeemon wrote:

On Saturday, 6 January 2018 at 06:47:33 UTC, Vino wrote:

[...]


Here's a version with Array, it's very similar:

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;
import std.file : readText;
import std.container.array;

[...]


Hi Deemon,

 Thank you very much, moving to second phase.

From,
Vino.B


Hi Deemon,

 Just noticed that the output writes the data and key as 2 values 
, but the requirnment is to write to six files, e.g


Data File 1
["Baker", "John", "Johnson", "Jones", "Miller", "Millers", 
"Millman", "Zsuwalski"]


Key File 1
[4, 1, 6, 7, 0, 4, 3, 4, 2, 1, 6, 5]

Data File 2
["America", "Austrilia", "Canada", "Chile", "China", "India", 
"Japan", "Netherlands"]


Key File 2
[0, 5, 1, 6, 4, 2, 1, 5, 7, 0, 4, 3]

Data File 3
[18, 21, 23, 42, 45]

Key File 3
[2, 3, 1, 4, 4, 2, 0, 1, 3, 3, 3, 2]

From,
Vino.B


Finding ElementType

2018-01-07 Thread Bastiaan Veelo via Digitalmars-d-learn
The learn forum is great not only for asking questions, but also 
for learning from the questions by others: I just learned about 
the existence of std.range.primitives: ElementType, a function 
that I have looked for in phobos before, without finding it. I 
had expected this to be in std.traits or __traits.


So I implemented my own:
```
template arrayElementType(T : T[])
{
alias arrayElementType = T;
}

unittest
{
static assert (is(arrayElementType!(int[]) == int));
}
```

For reference, this is the phobos version:
```
template ElementType(R)
{
static if (is(typeof(R.init.front.init) T))
alias ElementType = T;
else
alias ElementType = void;
}
```

As far as I can see these are largely equivalent, except that the 
phobos version has special behavior for narrow strings [1]. This 
special behavior is actually unwanted in my case.


The following questions pop up:
1) Should we have a reference in the docs for std.traits to 
std.range.primitive : ElementType?
2) Should phobos contain a version without the special narrow 
string behavior?
3) Are there other differences between my version and the phobos 
version?


Thanks,
Bastiaan.

[1] https://dlang.org/phobos/std_range_primitives.html#ElementType


Re: Passing Template to Function

2018-01-07 Thread Vino via Digitalmars-d-learn

On Saturday, 6 January 2018 at 15:26:30 UTC, Vino wrote:

Hi All,

 Request you help on the below program as it error out with the 
below error


[...]


Hi All,

 Thank you was able to resolve the issue.

From,
Vino.B


Re: Error: variable i cannot be read at compile time

2018-01-07 Thread Vino via Digitalmars-d-learn

On Saturday, 6 January 2018 at 15:32:14 UTC, thedeemon wrote:

On Saturday, 6 January 2018 at 06:47:33 UTC, Vino wrote:

[...]


Here's a version with Array, it's very similar:

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;
import std.file : readText;
import std.container.array;

[...]


Hi Deemon,

 Thank you very much, moving to second phase.

From,
Vino.B


Re: C++ Interop

2018-01-07 Thread Laeeth Isharc via Digitalmars-d-learn

On Saturday, 6 January 2018 at 11:17:56 UTC, Seb wrote:

On Friday, 5 January 2018 at 13:02:12 UTC, qznc wrote:
I'm exploring [0] C++ interop after watching Walter's 
presentation [1].


[...]


I know about this:

https://github.com/Remedy-Entertainment/binderoo

https://github.com/dlang/druntime/pull/1802


Binderoo currently is Windows only.  I am talking to Ethan about 
extending it to work on Linux too.  Let me know if any other 
features helpful to add (no promises, but we can see).


Re: -L--demangle=dlang doesn't work

2018-01-07 Thread Venkat via Digitalmars-d-learn
Yes, thanks Mike. I have 2.24 installed. Now I have to figure out 
how I can upgrade binutils without a distro upgrade. :)