Should `dub run` prints its output to STDERR?

2017-09-08 Thread Ky-Anh Huynh via Digitalmars-d-learn
When I execute a program thanks to dub, `dub` also prints its 
information to STDOUT:


[code]
$ dub run dusybox:jq -- .status "   1" < 
/home/pi/df/acces.log |head -10

Building package dusybox:jq in /home/pi/projects/icy/dusybox/
Performing "debug" build using dmd for x86_64.
dusybox:jq ~master: target for configuration "application" is up 
to date.

To force a rebuild of up-to-date targets, run again with --force.
Running ./dusybox_jq .status1
4031
4031
3021
[/code]

Those first 5 lines are generated by `dub` and written to STDOUT. 
This is a bit inconvenient if I want to use my program output as 
input for another program.


We may have the same program if `dub` writes to STDERR. But it's 
more sense that a pipe program uses STDIN for input. This is a 
popular behavior I think.


Is there any option other than redirecting which depends on shell 
support?


Thanks,


Re: erros em printf[AJUDA]

2017-09-08 Thread dark777 via Digitalmars-d-learn

On Friday, 8 September 2017 at 23:04:07 UTC, kinke wrote:

On Friday, 8 September 2017 at 22:30:16 UTC, dark777 wrote:
ex3.d(19): Error: cannot pass dynamic arrays to extern(C) 
vararg functions


printf("Writef Hello %.*s!\n", name.length, name.ptr);


puts por que é mais chato o printf aqui na linguagem D do que no 
C?


Unit-tests with stderr / stdout

2017-09-08 Thread Ky-Anh Huynh via Digitalmars-d-learn

Hi,

As a system administrator I often have some small scripts/ 
programs that consume input and produce output for other system 
utilities. Something like `my_foo_program | awk ... | 
other_program`. As the tools write to STDOUT/STDERR, I haven't 
found a way to write unit tests for them. Should I write library 
instead? Is there any framework to write (smoke) tests that 
supports standard output devices?


Thanks for your reading.


Inout table

2017-09-08 Thread nkm1 via Digitalmars-d-learn
There is this little table in 
https://dlang.org/spec/function.html#inout-functions:


Common qualifier of the two type qualifiers
   mutable const  immutable inout inout const
mutable (= m)  m   c  c c c
const (= c)c   c  c c c
immutable (= i)c   c  i wcwc
inout (= w)c   c  wcw wc
inout const (= wc) c   c  wcwcwc

I don't understand what it is trying to say. What is it that is 
calculated here? The qualifier for the return value?

And what's an "inout const"?


Re: Deprecation: std.container.array.RangeT(A) is not visible from module Size

2017-09-08 Thread Ali Çehreli via Digitalmars-d-learn

On 09/08/2017 11:21 AM, Vino.B wrote:

> One final help on how to print the below
> output , just in case if this issue is fixed in next release,
>
> Output:
> [Tuple!string("C:\\Temp\\sapnas2\\BACKUP\\dir1"),
> Tuple!string("C:\\Temp\\sapnas2\\BACKUP\\DND5")][34, 4]
>
> Required output:
> C:\\Temp\\sapnas2\\BACKUP\\dir1 34
> C:\\Temp\\sapnas2\\BACKUP\\DND5  4

std.algorithm.zip can help:

void main () {
auto results = coSizeDirList();
auto dirs = results[][0];// A range
auto sizes = results[][1];   // Another range
auto combined = zip(dirs, sizes);// Corresponding elements linked

foreach (result; combined) {
auto dir = result[0]; // The element from the first range
auto size = result[1];// The element from the second range
writefln("%-40s %20s", dir, size);
}
}

Ali



Re: erros em printf[AJUDA]

2017-09-08 Thread kinke via Digitalmars-d-learn

On Friday, 8 September 2017 at 22:30:16 UTC, dark777 wrote:
ex3.d(19): Error: cannot pass dynamic arrays to extern(C) 
vararg functions


printf("Writef Hello %.*s!\n", name.length, name.ptr);


erros em printf[AJUDA]

2017-09-08 Thread dark777 via Digitalmars-d-learn
estava rodando este programa porem acrescentei o printf mas como 
resolver o erro?


bash-4.4$ rdmd ex3
ex3.d(19): Error: cannot pass dynamic arrays to extern(C) vararg 
functions

Failed: ["dmd", "-v", "-o-", "ex3.d", "-I."]


import std.stdio;
import std.string; //strip
import core.stdc.stdio;

//more informations: http://ddili.org/ders/d.en/strings.html

void main()
{
//char[] name;


write("What is your name? ");
//readln(name); //acept vector de char on input readln
//name = strip(name);  //Hello String!← no new-line 
character


string name = readln().strip(); // read string and no new 
line strip


write("Write Hello ", name, "!\n");
printf("Writef Hello %s!\n", name);
writef("Writef Hello %s!\n", name);
writeln("Writeln Hello ", name, "!");
writefln("Writefln Hello %s!", name);
}


Re: Anonymous nogc class

2017-09-08 Thread Jiyan via Digitalmars-d-learn

On Friday, 8 September 2017 at 16:10:55 UTC, Biotronic wrote:

On Friday, 8 September 2017 at 12:32:35 UTC, Jiyan wrote:

[...]


It's scoped!T's destructor. If you decide to use that 
workaround, you should probably copy scoped!T from std.typecons 
and have your own version. It's not safe in all cases, and the 
next standard library update might break it.



[...]


In your case, scoped!T is can be safely called from @nogc code, 
and thus could be marked @nogc. However, when a class C has a 
destructor that allocates, scoped!C could not be @nogc. So in 
order to be safe in all cases, it can't be @nogc in the general 
case.


--
  Biotronic


Thank you very much :)


Re: Problems with the DLangUI TreeWidget

2017-09-08 Thread Vadim Lopatin via Digitalmars-d-learn

On Friday, 8 September 2017 at 15:39:21 UTC, pezi_pink wrote:
On Friday, 8 September 2017 at 15:08:27 UTC, Vadim Lopatin 
wrote:

On Friday, 8 September 2017 at 12:10:23 UTC, pezi_pink wrote:

[...]


It's known issue:

https://github.com/buggins/dlangui/issues/278

Not sure if there is any workaround.



Ah, thanks for the reply. I did check the issues on git, 
obviously not well enough!


That's a shame, it renders (no pun intended) DLangUI basically 
useless for my project :(  maybe I will have to get the 
debugger out ...


Will try to fix it in a few days.


Re: Deprecation: std.container.array.RangeT(A) is not visible from module Size

2017-09-08 Thread Vino.B via Digitalmars-d-learn

On Friday, 8 September 2017 at 16:58:35 UTC, Ali Çehreli wrote:

On 09/08/2017 07:48 AM, Vino.B wrote:

> if
> std.container.array.RangeT(A) is deprecated

No, it's not deprecated. It's a private symbol of the 
std.container.array module. You shouldn't be able to use it at 
all. The fact that you are able to use it is due to a bug fix, 
which hasn't been fully activated yet. The bug is fixed but the 
compiler is still letting you use the symbol until the bug is 
effective in some future date.


In summary, you should not refer to RangeT in your code at all. 
Use auto return types if you have to but I'm happy to see that 
you've solved the remaining issues.


> subdirTotalGB = (subdirTotal/1024/1024); {
Subdir ~= d;

That should be MB, right? Kilo, mega, giga, etc.

Ali


Hi Ali,

 Sure, will wait for the fix, and for the line "subdirTotalGB = 
(subdirTotal/1024/1024); {
Subdir ~= d;" that's ok the issue  was rising from the line 
"string[][]" as you know std.container array do not have the 
capability of multi dimensional array hence i need to change it 
back from "Tuple!((Array!string), (Array!string)) Result;" which 
was causing the issue, will try it once again once the issue is 
fixed. Once again thank you very much for you help. One final 
help on how to print the below output , just in case if this 
issue is fixed in next release,


Output:
[Tuple!string("C:\\Temp\\sapnas2\\BACKUP\\dir1"),  
Tuple!string("C:\\Temp\\sapnas2\\BACKUP\\DND5")][34, 4]


Required output:
C:\\Temp\\sapnas2\\BACKUP\\dir1 34
C:\\Temp\\sapnas2\\BACKUP\\DND5  4

From,
Vino.B




Re: Deprecation: std.container.array.RangeT(A) is not visible from module Size

2017-09-08 Thread Ali Çehreli via Digitalmars-d-learn

On 09/08/2017 07:48 AM, Vino.B wrote:

> if
> std.container.array.RangeT(A) is deprecated

No, it's not deprecated. It's a private symbol of the 
std.container.array module. You shouldn't be able to use it at all. The 
fact that you are able to use it is due to a bug fix, which hasn't been 
fully activated yet. The bug is fixed but the compiler is still letting 
you use the symbol until the bug is effective in some future date.


In summary, you should not refer to RangeT in your code at all. Use auto 
return types if you have to but I'm happy to see that you've solved the 
remaining issues.


> subdirTotalGB = (subdirTotal/1024/1024); { Subdir ~= d;

That should be MB, right? Kilo, mega, giga, etc.

Ali



Re: Deprecation: std.container.array.RangeT(A) is not visible from module Size

2017-09-08 Thread Vino.B via Digitalmars-d-learn

On Friday, 8 September 2017 at 15:47:39 UTC, Vino.B wrote:

On Friday, 8 September 2017 at 14:48:38 UTC, Vino.B wrote:

Hi All,

  The below code output's the below warning, so if 
std.container.array.RangeT(A) is deprecated then what is the 
equivalent for this, request your help on this.


Warning :
Size.d(10): Deprecation: std.container.array.RangeT(A) is not 
visible from module Size
Size.d(10): Deprecation: std.container.array.RangeT(A) is not 
visible from module Size
Size.d(10): Deprecation: std.container.array.RangeT(A) is not 
visible from module Size
Size.d(10): Deprecation: std.container.array.RangeT(A) is not 
visible from module Size
["C:\\Temp\\sapnas2\\BACKUP\\dir1", 
"C:\\Temp\\sapnas2\\BACKUP\\DND3", 
"C:\\Temp\\sapnas2\\BACKUP\\DND5"][34, 1, 5]


Code:
import std.algorithm: filter, map, fold;
import std.container;
import std.file: SpanMode, dirEntries, isDir, isFile;
import std.stdio: File, writefln, writeln;
import std.typecons: tuple, Tuple;
import std.parallelism: parallel;
import std.conv;
import std.range;

Tuple!(RangeT!(Array!string), RangeT!(Array!ulong)) 
coSizeDirList () {

string FFs = "C:\\Temp\\sapnas2\\BACKUP";
int SizeDir = 1;
ulong subdirTotal;
ulong subdirTotalGB;
Array!(string) Subdir;
Array!(ulong) Subsize;
Tuple!((Array!string), (Array!string)) Result;
	auto dFiles = Array!string ((dirEntries(FFs, 
SpanMode.shallow).filter!(a => a.isDir))[].map!(a => a.name));

foreach (d; dFiles[]) {
auto SdFiles = Array!ulong(dirEntries(d, 
SpanMode.depth).map!(a => a.size));

foreach(f; SdFiles[]) { subdirTotal += f; }
subdirTotalGB = (subdirTotal/1024/1024); { Subdir ~= d; 
Subsize ~= subdirTotalGB; }

if (subdirTotalGB > SizeDir)
subdirTotal = 0;
}
return tuple (Subdir[], Subsize[]);

}

void main () {
writeln(coSizeDirList[]);
}

From,
Vino.B


Hi All,

 Was able to resolve the above issue but not sure whether it is 
correct and now i am getting the output as below, request your 
help.

Output:
C:\Temp\sapnas2\BACKUP\dir1, 34, C:\Temp\sapnas2\BACKUP\DND3, 
1, C:\Temp\sapnas2\BACKUP\DND5, 5


Required Output:
C:\Temp\sapnas2\BACKUP\dir134
C:\Temp\sapnas2\BACKUP\DND3 1
C:\Temp\sapnas2\BACKUP\DND5 5

Program:
import std.algorithm: filter, map, fold;
import std.container;
import std.file: SpanMode, dirEntries, isDir, isFile;
import std.stdio: File, writefln, writeln;
import std.typecons: tuple, Tuple;
import std.parallelism: parallel;
import std.conv;
import std.range;

Array!string coSizeDirList () {
string FFs = "C:\\Temp\\sapnas2\\BACKUP";
int SizeDir = 1;
ulong subdirTotal;
ulong subdirTotalGB;
Array!(string) Subsize;
Array!string Result;
	auto dFiles = Array!string ((dirEntries(FFs, 
SpanMode.shallow).filter!(a => a.isDir))[].map!(a => a.name));

foreach (d; dFiles[]) {
auto SdFiles = Array!ulong(dirEntries(d, 
SpanMode.depth).map!(a => a.size));

foreach(f; SdFiles[]) { subdirTotal += f; }
subdirTotalGB = (subdirTotal/1024/1024); { Result ~= d; 
Result ~= to!string(subdirTotalGB); }

if (subdirTotalGB > SizeDir)
subdirTotal = 0;
}
return Result;
}

void main () {
writefln("%-(%s, %)", coSizeDirList[]);
}

From,
Vino.B


Hi All,

 At last was able to resolve the issue including the output too, 
thank you very much for your help, please let me know in case if 
you find any issue with the below code.


import std.algorithm: filter, map;
import std.container;
import std.file: SpanMode, dirEntries, isDir, isFile;
import std.stdio: File, writefln, writeln;
import std.typecons: tuple, Tuple;
import std.parallelism: parallel;
import std.conv;
import std.range;

string[][] coSizeDirList () {
string FFs = "C:\\Temp\\sapnas2\\BACKUP";
int SizeDir = 1;
ulong subdirTotal;
ulong subdirTotalGB;
Array!(string) Subsize;
string[][] Result;
	auto dFiles = Array!string ((dirEntries(FFs, 
SpanMode.shallow).filter!(a => a.isDir))[].map!(a => a.name));

foreach (d; dFiles[]) {
auto SdFiles = Array!ulong(dirEntries(d, 
SpanMode.depth).map!(a => a.size));

foreach(f; SdFiles[]) { subdirTotal += f; }
subdirTotalGB = (subdirTotal/1024/1024);
if (subdirTotalGB > SizeDir) { Result ~= [[d] ~ 
[to!string(subdirTotalGB)]]; }

subdirTotal = 0;
}
return Result;
}

void main () {
writefln("%(%-(%-63s %)\n%)", coSizeDirList[]);
}

From,
Vino.B


Re: Container Array

2017-09-08 Thread Vino.B via Digitalmars-d-learn

On Friday, 8 September 2017 at 15:48:47 UTC, Vino.B wrote:

On Friday, 8 September 2017 at 12:14:46 UTC, Vino.B wrote:

On Friday, 8 September 2017 at 09:51:38 UTC, Ali Çehreli wrote:

[...]


Hi Ali,

  As stated earlier my release 1 code are still using 
std.array, so now in release 2 i am converting all my standard 
array to container array. My program has 5 function and I was 
able to adopt 4 function to container array, and facing issue 
with this 1 function. I would like to have all my function to 
be neither in standard array nor in container array, more over 
I am facing gc issue in standard array and this is the main 
reason I would like to convert my function to container array, 
as this function would find the size of folder which are 
greater then a specified size in a 5 file system each with 10 
TB, so i have added the thread(with Local storage) and 
parallelism to my function as container array give's me the 
option of reserving memory, so that i would bump it up as and 
when it is required with any gc issues. All help to resolve 
this issue would be appreciated.


Updated Code:
import std.algorithm: filter, map, fold;
import std.container;
import std.file: SpanMode, dirEntries, isDir;
import std.stdio: File, writefln, writeln;
import std.typecons: tuple, Tuple;
import std.parallelism: parallel;
import std.conv;
import std.range;

Tuple!(RangeT!(Array!string), RangeT!(Array!ulong)) 
coSizeDirList () {

string FFs = "C:\\Temp\\sapnas2\\BACKUP";
int SizeDir = 1;
ulong subdirTotal;
ulong subdirTotalGB;
Array!(string) Subdir;
Array!(ulong) Subsize;
Tuple!((Array!string), (Array!string)) Result;
	auto dFiles = Array!string ((dirEntries(FFs, 
SpanMode.shallow).filter!(a => a.isDir))[].map!(a => a.name));

foreach (d; dFiles[]) {
auto SdFiles = Array!ulong ((dirEntries(d, 
SpanMode.depth)).map!(a => a.size));

foreach(f; SdFiles[]) { subdirTotal += f; }
	subdirTotalGB = (subdirTotal/1024/1024); { Subdir ~= d; 
Subsize ~= subdirTotalGB; }

if (subdirTotalGB > SizeDir)
subdirTotal = 0;
}
return tuple (Subdir[], Subsize[]);
}

void main () {
writeln(coSizeDirList[]);
}

From,
Vino.B


Hi Ali,

 Was able to resolve the above issue but not sure whether it is 
correct and now i am getting the output as below, request your 
help.


Output:
C:\Temp\sapnas2\BACKUP\dir1, 34, C:\Temp\sapnas2\BACKUP\DND3, 
1, C:\Temp\sapnas2\BACKUP\DND5, 5


Required Output:
C:\Temp\sapnas2\BACKUP\dir134
C:\Temp\sapnas2\BACKUP\DND3 1
C:\Temp\sapnas2\BACKUP\DND5 5

Program:
import std.algorithm: filter, map, fold;
import std.container;
import std.file: SpanMode, dirEntries, isDir, isFile;
import std.stdio: File, writefln, writeln;
import std.typecons: tuple, Tuple;
import std.parallelism: parallel;
import std.conv;
import std.range;

Array!string coSizeDirList () {
string FFs = "C:\\Temp\\sapnas2\\BACKUP";
int SizeDir = 1;
ulong subdirTotal;
ulong subdirTotalGB;
Array!(string) Subsize;
Array!string Result;
	auto dFiles = Array!string ((dirEntries(FFs, 
SpanMode.shallow).filter!(a => a.isDir))[].map!(a => a.name));

foreach (d; dFiles[]) {
auto SdFiles = Array!ulong(dirEntries(d, 
SpanMode.depth).map!(a => a.size));

foreach(f; SdFiles[]) { subdirTotal += f; }
subdirTotalGB = (subdirTotal/1024/1024); { Result ~= d; 
Result ~= to!string(subdirTotalGB); }

if (subdirTotalGB > SizeDir)
subdirTotal = 0;
}
return Result;
}

void main () {
writefln("%-(%s, %)", coSizeDirList[]);
}

From,
Vino.B


Hi Ali,

 At last was able to resolve the issue including the output too, 
thank you very much for your help, please let me know in case if 
you find any issue with the below code.


import std.algorithm: filter, map, fold;
import std.container;
import std.file: SpanMode, dirEntries, isDir, isFile;
import std.stdio: File, writefln, writeln;
import std.typecons: tuple, Tuple;
import std.parallelism: parallel;
import std.conv;
import std.range;

string[][] coSizeDirList () {
string FFs = "C:\\Temp\\sapnas2\\BACKUP";
int SizeDir = 1;
ulong subdirTotal;
ulong subdirTotalGB;
Array!(string) Subsize;
string[][] Result;
	auto dFiles = Array!string ((dirEntries(FFs, 
SpanMode.shallow).filter!(a => a.isDir))[].map!(a => a.name));

foreach (d; dFiles[]) {
auto SdFiles = Array!ulong(dirEntries(d, 
SpanMode.depth).map!(a => a.size));

foreach(f; SdFiles[]) { subdirTotal += f; }
subdirTotalGB = (subdirTotal/1024/1024);
if (subdirTotalGB > SizeDir) { Result ~= 

Re: Anonymous nogc class

2017-09-08 Thread Biotronic via Digitalmars-d-learn

On Friday, 8 September 2017 at 12:32:35 UTC, Jiyan wrote:

On Friday, 8 September 2017 at 06:37:54 UTC, Biotronic wrote:

On Thursday, 7 September 2017 at 23:40:11 UTC, Jiyan wrote:

[...]


Sadly, even std.typecons.scoped isn't currently @nogc:
https://issues.dlang.org/show_bug.cgi?id=13972
https://issues.dlang.org/show_bug.cgi?id=17592

[...]


First thanks :)

i understand the part with scopedAnon, but can you explain what 
the ~this is referring to?

Is it the Modul destructor?


It's scoped!T's destructor. If you decide to use that workaround, 
you should probably copy scoped!T from std.typecons and have your 
own version. It's not safe in all cases, and the next standard 
library update might break it.


And in general is it just that scoped is just not marked @nogc 
or is it that it would really need to use the gc?


In your case, scoped!T is can be safely called from @nogc code, 
and thus could be marked @nogc. However, when a class C has a 
destructor that allocates, scoped!C could not be @nogc. So in 
order to be safe in all cases, it can't be @nogc in the general 
case.


--
  Biotronic


Re: Container Array

2017-09-08 Thread Vino.B via Digitalmars-d-learn

On Friday, 8 September 2017 at 12:14:46 UTC, Vino.B wrote:

On Friday, 8 September 2017 at 09:51:38 UTC, Ali Çehreli wrote:

On 09/07/2017 11:21 PM, Vino.B wrote:

>   At last was able to print the output, but i am getting some
> "Deprecation" warnings like below and also can you help me in
formating
> the output to display ulong.
>
> Output:
> Size.d(9): Deprecation: std.container.array.RangeT(A) is not
visible
> from module Size

That's due to std.container.array.RangeT being private. The 
deprecation warning is about a bug that leaked such private 
symbols when they were imported selectively (I think). Now the 
bug is fixed, you won't be able to access the symbol at the 
end of the deprecation period.


> import std.algorithm: filter, map, fold;
> import std.container;
> import std.file: SpanMode, dirEntries, isDir;
> import std.stdio: File, writefln, writeln;
> import std.typecons: tuple, Tuple;
> import std.parallelism: parallel;
> import std.conv;
> import std.range;
> Tuple!(RangeT!(Array!(Tuple!string)), RangeT!(Array!ulong))
> coSizeDirList () {
> string FFs = "C:\\Temp\\sapnas2\\BACKUP";
> int SizeDir = 1;
> ulong subdirTotal;
> ulong subdirTotalGB;
> Array!(ulong) Subdata;
> auto dFiles = Array!(Tuple!(string)) (dirEntries(FFs,
> SpanMode.shallow).filter!(a => a.isDir).map!(a =>
tuple(a.name)));
> foreach (d; dFiles[]) {
> auto SdFiles = Array!(Tuple!(ulong))
(dirEntries(d[0],
> SpanMode.depth).map!(a => tuple(a.size)));
> foreach(f; SdFiles[]) { subdirTotal +=
f.fold!((a, b) =>
> a + b); }
> subdirTotalGB = (subdirTotal/1024/1024);
> if (subdirTotalGB > SizeDir) { Subdata ~=
> subdirTotalGB; }
> subdirTotal = 0;
> }
> return tuple (dFiles[], Subdata[]);
> }
>
> void main () {
> writeln(coSizeDirList[]);
> //writefln("%(%-(%-63s %)\n%)", coSizeDirList[]);
> }

I apologize for not really having time to look at what you're 
trying to achieve. I gave you advice which ended up trying to 
solve compilation errors.


I think the main problem here is to determine directories 
above a certain size. So, I think Array should enter the 
picture only if built-in arrays are not usable for some 
reason. Even better, one should stay with lazy range 
algorithms as long as it's possible.


How about the following approach, which you can either use 
directly or populate an Array with:


import std.algorithm: filter, map, sum;
import std.file: SpanMode, dirEntries, isDir, DirEntry;
import std.stdio: writeln;

auto dFiles(string dirName) {
return dirEntries(dirName, SpanMode.shallow).filter!(a => 
a.isDir);

}

auto totalSize(DirEntry dir) {
return dirEntries(dir, SpanMode.depth).map!(a => 
a.size).sum;

}

struct DirInfo {
string name;
ulong size;
}

auto coSizeDirList (string dirName, ulong sizeLimit) {
return dFiles(dirName).map!(dir => DirInfo(dir.name, 
dir.totalSize)).filter!(info => info.size > sizeLimit);

}

void main () {
writeln(coSizeDirList("./deleteme", 1));

// Only if Array is really needed:
import std.container : Array;
auto arr = Array!DirInfo(coSizeDirList("./deleteme", 42));
writeln(arr[]);
}

Ali


Hi Ali,

  As stated earlier my release 1 code are still using 
std.array, so now in release 2 i am converting all my standard 
array to container array. My program has 5 function and I was 
able to adopt 4 function to container array, and facing issue 
with this 1 function. I would like to have all my function to 
be neither in standard array nor in container array, more over 
I am facing gc issue in standard array and this is the main 
reason I would like to convert my function to container array, 
as this function would find the size of folder which are 
greater then a specified size in a 5 file system each with 10 
TB, so i have added the thread(with Local storage) and 
parallelism to my function as container array give's me the 
option of reserving memory, so that i would bump it up as and 
when it is required with any gc issues. All help to resolve 
this issue would be appreciated.


Updated Code:
import std.algorithm: filter, map, fold;
import std.container;
import std.file: SpanMode, dirEntries, isDir;
import std.stdio: File, writefln, writeln;
import std.typecons: tuple, Tuple;
import std.parallelism: parallel;
import std.conv;
import std.range;

Tuple!(RangeT!(Array!string), RangeT!(Array!ulong)) 
coSizeDirList () {

string FFs = "C:\\Temp\\sapnas2\\BACKUP";
int SizeDir = 1;
ulong subdirTotal;
ulong subdirTotalGB;
Array!(string) Subdir;
Array!(ulong) Subsize;
Tuple!((Array!string), (Array!string)) Result;
	auto dFiles = Array!string ((dirEntries(FFs, 
SpanMode.shallow).filter!(a => a.isDir))[].map!(a => a.name));

foreach (d; dFiles[]) {
auto SdFiles = Array!ulong ((dirEntries(d, 
SpanMode.depth)).map!(a => a.size));


Re: Deprecation: std.container.array.RangeT(A) is not visible from module Size

2017-09-08 Thread Vino.B via Digitalmars-d-learn

On Friday, 8 September 2017 at 14:48:38 UTC, Vino.B wrote:

Hi All,

  The below code output's the below warning, so if 
std.container.array.RangeT(A) is deprecated then what is the 
equivalent for this, request your help on this.


Warning :
Size.d(10): Deprecation: std.container.array.RangeT(A) is not 
visible from module Size
Size.d(10): Deprecation: std.container.array.RangeT(A) is not 
visible from module Size
Size.d(10): Deprecation: std.container.array.RangeT(A) is not 
visible from module Size
Size.d(10): Deprecation: std.container.array.RangeT(A) is not 
visible from module Size
["C:\\Temp\\sapnas2\\BACKUP\\dir1", 
"C:\\Temp\\sapnas2\\BACKUP\\DND3", 
"C:\\Temp\\sapnas2\\BACKUP\\DND5"][34, 1, 5]


Code:
import std.algorithm: filter, map, fold;
import std.container;
import std.file: SpanMode, dirEntries, isDir, isFile;
import std.stdio: File, writefln, writeln;
import std.typecons: tuple, Tuple;
import std.parallelism: parallel;
import std.conv;
import std.range;

Tuple!(RangeT!(Array!string), RangeT!(Array!ulong)) 
coSizeDirList () {

string FFs = "C:\\Temp\\sapnas2\\BACKUP";
int SizeDir = 1;
ulong subdirTotal;
ulong subdirTotalGB;
Array!(string) Subdir;
Array!(ulong) Subsize;
Tuple!((Array!string), (Array!string)) Result;
	auto dFiles = Array!string ((dirEntries(FFs, 
SpanMode.shallow).filter!(a => a.isDir))[].map!(a => a.name));

foreach (d; dFiles[]) {
auto SdFiles = Array!ulong(dirEntries(d, 
SpanMode.depth).map!(a => a.size));

foreach(f; SdFiles[]) { subdirTotal += f; }
subdirTotalGB = (subdirTotal/1024/1024); { Subdir ~= d; 
Subsize ~= subdirTotalGB; }

if (subdirTotalGB > SizeDir)
subdirTotal = 0;
}
return tuple (Subdir[], Subsize[]);

}

void main () {
writeln(coSizeDirList[]);
}

From,
Vino.B


Hi All,

 Was able to resolve the above issue but not sure whether it is 
correct and now i am getting the output as below, request your 
help.

Output:
C:\Temp\sapnas2\BACKUP\dir1, 34, C:\Temp\sapnas2\BACKUP\DND3, 1, 
C:\Temp\sapnas2\BACKUP\DND5, 5


Required Output:
C:\Temp\sapnas2\BACKUP\dir134
C:\Temp\sapnas2\BACKUP\DND3 1
C:\Temp\sapnas2\BACKUP\DND5 5

Program:
import std.algorithm: filter, map, fold;
import std.container;
import std.file: SpanMode, dirEntries, isDir, isFile;
import std.stdio: File, writefln, writeln;
import std.typecons: tuple, Tuple;
import std.parallelism: parallel;
import std.conv;
import std.range;

Array!string coSizeDirList () {
string FFs = "C:\\Temp\\sapnas2\\BACKUP";
int SizeDir = 1;
ulong subdirTotal;
ulong subdirTotalGB;
Array!(string) Subsize;
Array!string Result;
	auto dFiles = Array!string ((dirEntries(FFs, 
SpanMode.shallow).filter!(a => a.isDir))[].map!(a => a.name));

foreach (d; dFiles[]) {
auto SdFiles = Array!ulong(dirEntries(d, 
SpanMode.depth).map!(a => a.size));

foreach(f; SdFiles[]) { subdirTotal += f; }
subdirTotalGB = (subdirTotal/1024/1024); { Result ~= d; 
Result ~= to!string(subdirTotalGB); }

if (subdirTotalGB > SizeDir)
subdirTotal = 0;
}
return Result;
}

void main () {
writefln("%-(%s, %)", coSizeDirList[]);
}

From,
Vino.B





Re: Problems with the DLangUI TreeWidget

2017-09-08 Thread pezi_pink via Digitalmars-d-learn

On Friday, 8 September 2017 at 15:08:27 UTC, Vadim Lopatin wrote:

On Friday, 8 September 2017 at 12:10:23 UTC, pezi_pink wrote:

[...]


It's known issue:

https://github.com/buggins/dlangui/issues/278

Not sure if there is any workaround.



Ah, thanks for the reply. I did check the issues on git, 
obviously not well enough!


That's a shame, it renders (no pun intended) DLangUI basically 
useless for my project :(  maybe I will have to get the debugger 
out ...


Re: DLang IDE [RU]

2017-09-08 Thread Vadim Lopatin via Digitalmars-d-learn

On Thursday, 7 September 2017 at 12:24:40 UTC, TM wrote:
Это понятно, что у Java своя организационная специфика, в 
принципе если в диалоге создание файла минимизировать 
количество кликов, то есть сразу вводишь имя файла с клавиатуры 
и кнопка создания будет реагировать на Entrer (а не Ctrl+N), 
будет вполне юзабельно.


Сделал. Ctrl+N (type module name here) Enter
Должно быть удобно.

Новый релиз v0.7.71 - исправлено много замечаний.

Есть бинарник для Win32

https://github.com/buggins/dlangide/releases




Re: Problems with the DLangUI TreeWidget

2017-09-08 Thread Vadim Lopatin via Digitalmars-d-learn

On Friday, 8 September 2017 at 12:10:23 UTC, pezi_pink wrote:
I am having some seemingly basic problems using the TreeWidget 
from DLangUI on Windows.  I posted on the project's gitter 
channel some time ago but did not get any response.


All I am trying to do is add children to the tree's nodes at 
runtime.  The simple code below attempts to add a new node when 
a button is pressed.  As far as I can tell, the node does 
indeed get added, since the new node responds to keyboard 
events, but it does not render.  I have tried everything to get 
it to render, using all the available invalidate/redraw 
methods, even as far as removing and re-adding the control 
again to its layout, but nothing seems to work.  Any advice 
would be greatly received!


extern (C) int UIAppMain(string[] args) {
  auto window  = Platform.instance.createWindow("DlangUI 
example - HelloWorld", null);

  auto vlayout = new VerticalLayout();
  TreeWidget tree = new TreeWidget("Root");
  TreeItem tree2 = tree.items.newChild("machinesroot", 
"Machines"d, null);
  auto machine0 = tree2.newChild("machine0", "Machine 0"d, 
null);

  machine0.newChild("machine0stack", "Stack", null);
  auto btn = (new Button("btn1", "Button 1"d));
  btn.click = delegate(Widget src) {
// this gets added but does not render
tree2.newChild("machine1", "Machine 1"d, null);
return true;
  };
  vlayout.addChild(btn);
  vlayout.addChild(tree);
  window.mainWidget = vlayout;
  window.show();
  return Platform.instance.enterMessageLoop();
}

Thanks


It's known issue:

https://github.com/buggins/dlangui/issues/278

Not sure if there is any workaround.



Deprecation: std.container.array.RangeT(A) is not visible from module Size

2017-09-08 Thread Vino.B via Digitalmars-d-learn

Hi All,

  The below code output's the below warning, so if 
std.container.array.RangeT(A) is deprecated then what is the 
equivalent for this, request your help on this.


Warning :
Size.d(10): Deprecation: std.container.array.RangeT(A) is not 
visible from module Size
Size.d(10): Deprecation: std.container.array.RangeT(A) is not 
visible from module Size
Size.d(10): Deprecation: std.container.array.RangeT(A) is not 
visible from module Size
Size.d(10): Deprecation: std.container.array.RangeT(A) is not 
visible from module Size
["C:\\Temp\\sapnas2\\BACKUP\\dir1", 
"C:\\Temp\\sapnas2\\BACKUP\\DND3", 
"C:\\Temp\\sapnas2\\BACKUP\\DND5"][34, 1, 5]


Code:
import std.algorithm: filter, map, fold;
import std.container;
import std.file: SpanMode, dirEntries, isDir, isFile;
import std.stdio: File, writefln, writeln;
import std.typecons: tuple, Tuple;
import std.parallelism: parallel;
import std.conv;
import std.range;

Tuple!(RangeT!(Array!string), RangeT!(Array!ulong)) coSizeDirList 
() {

string FFs = "C:\\Temp\\sapnas2\\BACKUP";
int SizeDir = 1;
ulong subdirTotal;
ulong subdirTotalGB;
Array!(string) Subdir;
Array!(ulong) Subsize;
Tuple!((Array!string), (Array!string)) Result;
	auto dFiles = Array!string ((dirEntries(FFs, 
SpanMode.shallow).filter!(a => a.isDir))[].map!(a => a.name));

foreach (d; dFiles[]) {
auto SdFiles = Array!ulong(dirEntries(d, 
SpanMode.depth).map!(a => a.size));

foreach(f; SdFiles[]) { subdirTotal += f; }
subdirTotalGB = (subdirTotal/1024/1024); { Subdir ~= d; 
Subsize ~= subdirTotalGB; }

if (subdirTotalGB > SizeDir)
subdirTotal = 0;
}
return tuple (Subdir[], Subsize[]);

}

void main () {
writeln(coSizeDirList[]);
}

From,
Vino.B


Re: Is compiling for Android/iOS possible?

2017-09-08 Thread Joakim via Digitalmars-d-learn
On Wednesday, 6 September 2017 at 18:34:28 UTC, Timothy Foster 
wrote:
I'm just wondering if I made an application for 
Windows/Mac/Linux if I could get it to also work on mobile 
devices, or would I have to rewrite the application in another 
language to get it to work? If it's possible, what should I be 
looking at to get something like a "Hello World" example to 
show on my phone using D?


Backend code that does most of the work, ie your business logic, 
should work fine in D on mobile devices.  For the frontend, I 
don't know of a good touch-enabled GUI that you could use in D 
though.  If you're okay with doing your GUI in the native 
language, ie Java on Android, then calling D for the backend, 
that will work.  There has been some preliminary work on getting 
a D GUI library, DlangUI, working on Android, but my 
understanding is that it isn't touch-optimized:


http://forum.dlang.org/thread/cdekkumjynhqoxvmg...@forum.dlang.org

Ali gave you some good links to check out for simple apps on 
Android.  As for iOS, Dan was working on it, but he doesn't have 
time for it anymore, so it hasn't been kept up to date.


The upcoming ldc 1.4 official release will have easy support for 
Android, you can try it out with the current beta (you will need 
to cross-compile the stdlib for Android/ARM by using 
ldc-build-runtime, with a small tweak to druntime):


http://forum.dlang.org/thread/ojoyytdparflttnna...@forum.dlang.org

We're refining the build process for Android in the ldc 1.4 
betas, so chip in if you'd like to see that done well.


Re: Anonymous nogc class

2017-09-08 Thread Jiyan via Digitalmars-d-learn

On Friday, 8 September 2017 at 06:37:54 UTC, Biotronic wrote:

On Thursday, 7 September 2017 at 23:40:11 UTC, Jiyan wrote:

[...]


Sadly, even std.typecons.scoped isn't currently @nogc:
https://issues.dlang.org/show_bug.cgi?id=13972
https://issues.dlang.org/show_bug.cgi?id=17592

[...]


First thanks :)

i understand the part with scopedAnon, but can you explain what 
the ~this is referring to?

Is it the Modul destructor?
And in general is it just that scoped is just not marked @nogc or 
is it that it would really need to use the gc?


Re: Container Array

2017-09-08 Thread Vino.B via Digitalmars-d-learn

On Friday, 8 September 2017 at 09:51:38 UTC, Ali Çehreli wrote:

On 09/07/2017 11:21 PM, Vino.B wrote:

>   At last was able to print the output, but i am getting some
> "Deprecation" warnings like below and also can you help me in
formating
> the output to display ulong.
>
> Output:
> Size.d(9): Deprecation: std.container.array.RangeT(A) is not
visible
> from module Size

That's due to std.container.array.RangeT being private. The 
deprecation warning is about a bug that leaked such private 
symbols when they were imported selectively (I think). Now the 
bug is fixed, you won't be able to access the symbol at the end 
of the deprecation period.


> import std.algorithm: filter, map, fold;
> import std.container;
> import std.file: SpanMode, dirEntries, isDir;
> import std.stdio: File, writefln, writeln;
> import std.typecons: tuple, Tuple;
> import std.parallelism: parallel;
> import std.conv;
> import std.range;
> Tuple!(RangeT!(Array!(Tuple!string)), RangeT!(Array!ulong))
> coSizeDirList () {
> string FFs = "C:\\Temp\\sapnas2\\BACKUP";
> int SizeDir = 1;
> ulong subdirTotal;
> ulong subdirTotalGB;
> Array!(ulong) Subdata;
> auto dFiles = Array!(Tuple!(string)) (dirEntries(FFs,
> SpanMode.shallow).filter!(a => a.isDir).map!(a =>
tuple(a.name)));
> foreach (d; dFiles[]) {
> auto SdFiles = Array!(Tuple!(ulong))
(dirEntries(d[0],
> SpanMode.depth).map!(a => tuple(a.size)));
> foreach(f; SdFiles[]) { subdirTotal +=
f.fold!((a, b) =>
> a + b); }
> subdirTotalGB = (subdirTotal/1024/1024);
> if (subdirTotalGB > SizeDir) { Subdata ~=
> subdirTotalGB; }
> subdirTotal = 0;
> }
> return tuple (dFiles[], Subdata[]);
> }
>
> void main () {
> writeln(coSizeDirList[]);
> //writefln("%(%-(%-63s %)\n%)", coSizeDirList[]);
> }

I apologize for not really having time to look at what you're 
trying to achieve. I gave you advice which ended up trying to 
solve compilation errors.


I think the main problem here is to determine directories above 
a certain size. So, I think Array should enter the picture only 
if built-in arrays are not usable for some reason. Even better, 
one should stay with lazy range algorithms as long as it's 
possible.


How about the following approach, which you can either use 
directly or populate an Array with:


import std.algorithm: filter, map, sum;
import std.file: SpanMode, dirEntries, isDir, DirEntry;
import std.stdio: writeln;

auto dFiles(string dirName) {
return dirEntries(dirName, SpanMode.shallow).filter!(a => 
a.isDir);

}

auto totalSize(DirEntry dir) {
return dirEntries(dir, SpanMode.depth).map!(a => 
a.size).sum;

}

struct DirInfo {
string name;
ulong size;
}

auto coSizeDirList (string dirName, ulong sizeLimit) {
return dFiles(dirName).map!(dir => DirInfo(dir.name, 
dir.totalSize)).filter!(info => info.size > sizeLimit);

}

void main () {
writeln(coSizeDirList("./deleteme", 1));

// Only if Array is really needed:
import std.container : Array;
auto arr = Array!DirInfo(coSizeDirList("./deleteme", 42));
writeln(arr[]);
}

Ali


Hi Ali,

  As stated earlier my release 1 code are still using std.array, 
so now in release 2 i am converting all my standard array to 
container array. My program has 5 function and I was able to 
adopt 4 function to container array, and facing issue with this 1 
function. I would like to have all my function to be neither in 
standard array nor in container array, more over I am facing gc 
issue in standard array and this is the main reason I would like 
to convert my function to container array, as this function would 
find the size of folder which are greater then a specified size 
in a 5 file system each with 10 TB, so i have added the 
thread(with Local storage) and parallelism to my function as 
container array give's me the option of reserving memory, so that 
i would bump it up as and when it is required with any gc issues. 
All help to resolve this issue would be appreciated.


Updated Code:
import std.algorithm: filter, map, fold;
import std.container;
import std.file: SpanMode, dirEntries, isDir;
import std.stdio: File, writefln, writeln;
import std.typecons: tuple, Tuple;
import std.parallelism: parallel;
import std.conv;
import std.range;

Tuple!(RangeT!(Array!string), RangeT!(Array!ulong)) coSizeDirList 
() {

string FFs = "C:\\Temp\\sapnas2\\BACKUP";
int SizeDir = 1;
ulong subdirTotal;
ulong subdirTotalGB;
Array!(string) Subdir;
Array!(ulong) Subsize;
Tuple!((Array!string), (Array!string)) Result;
	auto dFiles = Array!string ((dirEntries(FFs, 
SpanMode.shallow).filter!(a => a.isDir))[].map!(a => a.name));

foreach (d; dFiles[]) {
auto SdFiles = Array!ulong ((dirEntries(d, 
SpanMode.depth)).map!(a => a.size));

foreach(f; SdFiles[]) { subdirTotal += f; }
	

Problems with the DLangUI TreeWidget

2017-09-08 Thread pezi_pink via Digitalmars-d-learn
I am having some seemingly basic problems using the TreeWidget 
from DLangUI on Windows.  I posted on the project's gitter 
channel some time ago but did not get any response.


All I am trying to do is add children to the tree's nodes at 
runtime.  The simple code below attempts to add a new node when a 
button is pressed.  As far as I can tell, the node does indeed 
get added, since the new node responds to keyboard events, but it 
does not render.  I have tried everything to get it to render, 
using all the available invalidate/redraw methods, even as far as 
removing and re-adding the control again to its layout, but 
nothing seems to work.  Any advice would be greatly received!


extern (C) int UIAppMain(string[] args) {
  auto window  = Platform.instance.createWindow("DlangUI example 
- HelloWorld", null);

  auto vlayout = new VerticalLayout();
  TreeWidget tree = new TreeWidget("Root");
  TreeItem tree2 = tree.items.newChild("machinesroot", 
"Machines"d, null);

  auto machine0 = tree2.newChild("machine0", "Machine 0"d, null);
  machine0.newChild("machine0stack", "Stack", null);
  auto btn = (new Button("btn1", "Button 1"d));
  btn.click = delegate(Widget src) {
// this gets added but does not render
tree2.newChild("machine1", "Machine 1"d, null);
return true;
  };
  vlayout.addChild(btn);
  vlayout.addChild(tree);
  window.mainWidget = vlayout;
  window.show();
  return Platform.instance.enterMessageLoop();
}

Thanks


Redirect STDOUT to socket (win32)

2017-09-08 Thread Maurizio Galeone via Digitalmars-d-learn

Hi,
is there any simple method to redirect STDOUT to socket?
All solutions I found until now (dup2, openNetwork) are available 
for linux only or have been deprecated.

Thanks in advance.
Best regards,
Maurizio


Re: Understanding gc memory profile report

2017-09-08 Thread Ali Çehreli via Digitalmars-d-learn


Although I responded below, I'm curious on what others think about this 
question.


On 09/08/2017 02:13 AM, John Burton wrote:
> I wrote this simple program to test out my understanding of memory
> allocation :-

I changed it to display the location and capacity:

import std.stdio;

void info(A)(A array) {
writefln("ptr: %s, capacity: %s, length: %s",
 array.ptr, array.capacity, array.length);
}

void main()
{
int [] array = new int[250];

info(array);

// Append one value to the array
array ~= 123;
info(array);
}

Sample output:

ptr: 7FD9B63CD000, capacity: 255, length: 250
ptr: 7FD9B63CD000, capacity: 255, length: 251

> I compiled it with 'dmd test.d -profile=gc'
>
> After running it, the profile report was :-
>
> bytes allocated, allocations, type, function, file:line
>2000   1 int[] D main test.d:5
>   4   1 int[] D main test.d:10

Here's my output with v2.076.0-dirty (that really is the version :o)):

   4000   1 int[] D main deneme.d:412
 72	  1	std.format.FormatException 
std.exception.enforceEx!(FormatException).enforceEx!bool.enforceEx 
/usr/include/dmd/phobos/std/exception.d:615
 64	  2	std.array.Appender!string.Appender.Data 
std.array.Appender!string.Appender.this 
/usr/include/dmd/phobos/std/array.d:2817
 32	  1 
std.array.Appender!(char[]).Appender.Data 
std.array.Appender!(char[]).Appender.this 
/usr/include/dmd/phobos/std/array.d:2817

  4   1 int[] D main deneme.d:417

And why is mine 4000 bytes? I guess it's the size of the underlying buffer.

> This is not how I expected it to be. I would have expected that the
> runtime either did not have to allocate at all at line 10 to add a new
> element because there was already space or it would have to allocate
> space for the new enlarged array and copy the array to it, in which case
> I'd expect it to allocate 2004 bytes (or more) to copy the enlarged
> array in to.
>
> I would not expect that it could have allocated 4 bytes to add an item
> separably from the original 2000. Is there some way that the runtime can
> grown the original allocation by 4 bytes and that's what I'm seeing? If
> so, is there a limit to how much it can do this?
>
> Can anyone help me understand what is going on here?

I think you're right. Perhaps more accurate information is not possible 
with the current implementation. Perhaps a higher-layer function counts 
"potential" allocations without being sure whether the space could be 
used for this slice or not. The "D Slices" article has related information:


  https://dlang.org/d-array-article.html

Ali



Re: Container Array

2017-09-08 Thread Ali Çehreli via Digitalmars-d-learn

On 09/07/2017 11:21 PM, Vino.B wrote:

>   At last was able to print the output, but i am getting some
> "Deprecation" warnings like below and also can you help me in formating
> the output to display ulong.
>
> Output:
> Size.d(9): Deprecation: std.container.array.RangeT(A) is not visible
> from module Size

That's due to std.container.array.RangeT being private. The deprecation 
warning is about a bug that leaked such private symbols when they were 
imported selectively (I think). Now the bug is fixed, you won't be able 
to access the symbol at the end of the deprecation period.


> import std.algorithm: filter, map, fold;
> import std.container;
> import std.file: SpanMode, dirEntries, isDir;
> import std.stdio: File, writefln, writeln;
> import std.typecons: tuple, Tuple;
> import std.parallelism: parallel;
> import std.conv;
> import std.range;
> Tuple!(RangeT!(Array!(Tuple!string)), RangeT!(Array!ulong))
> coSizeDirList () {
> string FFs = "C:\\Temp\\sapnas2\\BACKUP";
> int SizeDir = 1;
> ulong subdirTotal;
> ulong subdirTotalGB;
> Array!(ulong) Subdata;
> auto dFiles = Array!(Tuple!(string)) (dirEntries(FFs,
> SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name)));
> foreach (d; dFiles[]) {
> auto SdFiles = Array!(Tuple!(ulong)) (dirEntries(d[0],
> SpanMode.depth).map!(a => tuple(a.size)));
> foreach(f; SdFiles[]) { subdirTotal += f.fold!((a, b) =>
> a + b); }
> subdirTotalGB = (subdirTotal/1024/1024);
> if (subdirTotalGB > SizeDir) { Subdata ~=
> subdirTotalGB; }
> subdirTotal = 0;
> }
> return tuple (dFiles[], Subdata[]);
> }
>
> void main () {
> writeln(coSizeDirList[]);
> //writefln("%(%-(%-63s %)\n%)", coSizeDirList[]);
> }

I apologize for not really having time to look at what you're trying to 
achieve. I gave you advice which ended up trying to solve compilation 
errors.


I think the main problem here is to determine directories above a 
certain size. So, I think Array should enter the picture only if 
built-in arrays are not usable for some reason. Even better, one should 
stay with lazy range algorithms as long as it's possible.


How about the following approach, which you can either use directly or 
populate an Array with:


import std.algorithm: filter, map, sum;
import std.file: SpanMode, dirEntries, isDir, DirEntry;
import std.stdio: writeln;

auto dFiles(string dirName) {
return dirEntries(dirName, SpanMode.shallow).filter!(a => a.isDir);
}

auto totalSize(DirEntry dir) {
return dirEntries(dir, SpanMode.depth).map!(a => a.size).sum;
}

struct DirInfo {
string name;
ulong size;
}

auto coSizeDirList (string dirName, ulong sizeLimit) {
return dFiles(dirName).map!(dir => DirInfo(dir.name, 
dir.totalSize)).filter!(info => info.size > sizeLimit);

}

void main () {
writeln(coSizeDirList("./deleteme", 1));

// Only if Array is really needed:
import std.container : Array;
auto arr = Array!DirInfo(coSizeDirList("./deleteme", 42));
writeln(arr[]);
}

Ali



Understanding gc memory profile report

2017-09-08 Thread John Burton via Digitalmars-d-learn
I wrote this simple program to test out my understanding of 
memory allocation :-


import std.stdio;

void main()
{
int [] array = new int[250];

writeln(array.length, " elements ", array);

// Append one value to the array
array ~= 123;
writeln(array.length, " elements ", array);
}

I compiled it with 'dmd test.d -profile=gc'

After running it, the profile report was :-

bytes allocated, allocations, type, function, file:line
   2000   1 int[] D main test.d:5
  4   1 int[] D main test.d:10

This is not how I expected it to be. I would have expected that 
the runtime either did not have to allocate at all at line 10 to 
add a new element because there was already space or it would 
have to allocate space for the new enlarged array and copy the 
array to it, in which case I'd expect it to allocate 2004 bytes 
(or more) to copy the enlarged array in to.


I would not expect that it could have allocated 4 bytes to add an 
item separably from the original 2000. Is there some way that the 
runtime can grown the original allocation by 4 bytes and that's 
what I'm seeing? If so, is there a limit to how much it can do 
this?


Can anyone help me understand what is going on here?



Re: D is Multiplatform[DUVIDA]

2017-09-08 Thread maarten van damme via Digitalmars-d-learn
It's a compiled language, it'll behave like c++.

2017-09-08 7:13 GMT+02:00 dark777 via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com>:

> On Friday, 8 September 2017 at 03:56:25 UTC, rikki cattermole wrote:
>
>> On 08/09/2017 3:08 AM, dark777 wrote:
>>
>>> On Friday, 8 September 2017 at 00:09:08 UTC, solidstate1991 wrote:
>>>
 On Thursday, 7 September 2017 at 23:58:05 UTC, dark777 wrote:

> Good night, did you want to know this? Is the DE language
> cross-platform or cross-compile like C ++?
>

 GDC and LDC has multi-platform support, I'm currently working on an ARM
 backend for DMD.

>>>
>>> so does it mean that if I develop a program using the D language in BSD
>>> creating generic resources for example and compiling on windows, linux and
>>> darwin it would work fine?
>>>
>>
>> Each platform has its own unique behavior and related code.
>> Gotta try it to know for certain.
>>
>> But that is unrelated to D in the most part :)
>>
>
> but in any case then the D language can be considered multiplatform?
>


Re: Anonymous nogc class

2017-09-08 Thread Biotronic via Digitalmars-d-learn

On Thursday, 7 September 2017 at 23:40:11 UTC, Jiyan wrote:

Hey,
wanted to know whether it is possible to make anonymous nogc 
classes:


interface I
{
public void ap();
}
void exec(I i)
{
i.ap;
}

// now execute, but with something like `scope`
exec( new  class  I
{
int tr = 43;
override void ap(){tr.writeln;}
});

Thanks :)


Sadly, even std.typecons.scoped isn't currently @nogc:
https://issues.dlang.org/show_bug.cgi?id=13972
https://issues.dlang.org/show_bug.cgi?id=17592

This can be worked around by casting scoped's destructor to be 
@nogc, but that's a heavy-handed approach that ruins type safety, 
and is the wrong solution in non-@nogc situations. Should you 
want to, this is what it should look like:


~this()
{
(cast(void delegate(T) @nogc)((T t){
// `destroy` will also write .init but we have no 
functions in druntime
// for deterministic finalization and memory 
releasing for now.

.destroy(t);
}))(Scoped_payload);
}

If and when this issue is resolved, this should work:

interface I {
public void ap();
}

void exec(I i) {
i.ap;
}

auto scopedAnon(T)(lazy T dummy) if (is(T == class)) {
import std.typecons;
return scoped!T();
}

unittest {
auto i = scopedAnon(new class I {
int tr = 43;
override void ap() {
import std.stdio;
tr.writeln;
}
});
exec(i);
}

--
  Biotronic


Re: Container Array

2017-09-08 Thread Vino.B via Digitalmars-d-learn

On Thursday, 7 September 2017 at 20:47:43 UTC, Ali Çehreli wrote:

On 09/07/2017 10:39 AM, Vino.B wrote:

> Array!(Tuple!(string, ulong)) coSizeDirList () {

You stated the return type explicitly above.

> return tuple (dFiles[], Subdata[]);

According to the error message, what is being returned does not 
have the same type:


> Test1.d(27): Error: cannot implicitly convert expression
> (tuple(dFiles.opSlice(), Subdata.opSlice())) of type
> Tuple!(RangeT!(Array!(Tuple!string)), RangeT!(Array!ulong)) to
> Array!(Tuple!(string, ulong))

The actual return type is

Tuple!(RangeT!(Array!(Tuple!string)), RangeT!(Array!ulong))

There needs to be some transformations to match the two.

Ali


Hi Ali,

  At last was able to print the output, but i am getting some 
"Deprecation" warnings like below and also can you help me in 
formating the output to display ulong.


Output:
Size.d(9): Deprecation: std.container.array.RangeT(A) is not 
visible from module Size
Size.d(9): Deprecation: std.container.array.RangeT(A) is not 
visible from module Size
Size.d(9): Deprecation: std.container.array.RangeT(A) is not 
visible from module Size
Size.d(9): Deprecation: std.container.array.RangeT(A) is not 
visible from module Size
[Tuple!string("C:\\Temp\\sapnas2\\BACKUP\\dir1"), 
Tuple!string("C:\\Temp\\sapnas2\\BACKUP\\DND3"), 
Tuple!string("C:\\Temp\\sapnas2\\BACKUP\\DND5")][34, 4]


Program:
import std.algorithm: filter, map, fold;
import std.container;
import std.file: SpanMode, dirEntries, isDir;
import std.stdio: File, writefln, writeln;
import std.typecons: tuple, Tuple;
import std.parallelism: parallel;
import std.conv;
import std.range;
Tuple!(RangeT!(Array!(Tuple!string)), RangeT!(Array!ulong)) 
coSizeDirList () {

string FFs = "C:\\Temp\\sapnas2\\BACKUP";
int SizeDir = 1;
ulong subdirTotal;
ulong subdirTotalGB;
Array!(ulong) Subdata;
	auto dFiles = Array!(Tuple!(string)) (dirEntries(FFs, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name)));

foreach (d; dFiles[]) {
auto SdFiles = Array!(Tuple!(ulong)) (dirEntries(d[0], 
SpanMode.depth).map!(a => tuple(a.size)));
foreach(f; SdFiles[]) { subdirTotal += f.fold!((a, b) => a + 
b); }

subdirTotalGB = (subdirTotal/1024/1024);
if (subdirTotalGB > SizeDir) { Subdata 
~= subdirTotalGB; }
subdirTotal = 0;
}
return tuple (dFiles[], Subdata[]);
}

void main () {
writeln(coSizeDirList[]);
//writefln("%(%-(%-63s %)\n%)", coSizeDirList[]);
}