Parallel reads on std.container.array.Array

2017-12-07 Thread Arun Chandrasekaran via Digitalmars-d-learn
I was wondering if std.container.array.Array supports threadsafe 
parallel reads similar to std::vector. I've created a small 
program for demonstration 
https://github.com/carun/parallel-read-tester


It works fine with just couple of problems though:

1. D version takes way too long compared to C++ version.

```
bash build-and-run.sh
g++ (Ubuntu 7.2.0-8ubuntu3) 7.2.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  
There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A 
PARTICULAR PURPOSE.


LDC - the LLVM D compiler (1.6.0):
  based on DMD v2.076.1 and LLVM 5.0.0
  built with LDC - the LLVM D compiler (1.6.0)
  Default target: x86_64-unknown-linux-gnu
  Host CPU: skylake
  http://dlang.org - http://wiki.dlang.org/LDC

  Registered Targets:
aarch64- AArch64 (little endian)
aarch64_be - AArch64 (big endian)
arm- ARM
arm64  - ARM64 (little endian)
armeb  - ARM (big endian)
nvptx  - NVIDIA PTX 32-bit
nvptx64- NVIDIA PTX 64-bit
ppc32  - PowerPC 32
ppc64  - PowerPC 64
ppc64le- PowerPC 64 LE
thumb  - Thumb
thumbeb- Thumb (big endian)
x86- 32-bit X86: Pentium-Pro and above
x86-64 - 64-bit X86: EM64T and AMD64

=== Starting CPP version ===
Took 3.7583 to load 200 items. Gonna search in parallel...
5 400
6 400
2 400
0 400
1 400
7 400
4 400
3 400
Took 7.0247 to search

=== Starting D version ===
Took 1 sec, 506 ms, 672 μs, and 4 hnsecs to load 200 items. 
Gonna search in parallel...

3 400
4 400
2 400
6 400
7 400
5 400
1 400
0 400
Took 13 secs, 53 ms, 790 μs, and 3 hnsecs to search.
```
2. I'm on an 8 CPU box and I don't seem to hit 800% CPU with D 
version (max 720%). However I can get 800% CPU usage with the C++ 
version.


2. Introducing a string in the struct Data results in 
"std.container.Array.reserve failed to allocate memory", whereas 
adding a similar std::string in the C++ struct seems to work fine.


Am I missing anything obvious here?

Also why doesn't std.container.array support an equivalent of 
std::vector::erase?


Cheers,
Arun


Re: Create D portable binary

2017-12-07 Thread Adam D. Ruppe via Digitalmars-d-learn

On Friday, 8 December 2017 at 05:16:22 UTC, Fra Mecca wrote:
Is there a way to compile a project and deploying it as a 
single statically linked binary?


A default build of a D program is *reasonably* compatible. All 
its dependencies are core operating system components like libc. 
Now, there can certainly be libc version incompatibilities, but 
there's a decent chance it will just work.


I'm pretty sure this is the exact same situation Go is in; the 
default Go and D builds link the same way.



If you want to eliminate the potential C lib incompatibility too, 
you can do it basically the same way as in C, passing options to 
gcc with dmd's -L thing like `-L-static -L-nodefaultlib 
-L-lsome_alternate_clib`


Create D portable binary

2017-12-07 Thread Fra Mecca via Digitalmars-d-learn
Is there a way to compile a project and deploying it as a single 
statically linked binary?


My main target would be something like a self contained jar (like 
.war files), but something that is in the style of go binaries 
and portable to another Linux distribution without any hassle 
would be enough.


From what I understand the main problem in achieving this is the 
dependency to curl (all the warnings related to gethostbyname 
during linking phase) and glibc that makes it hard to static link.


What if musl is used as libc?

Right now it seems that the only viable option is to distribute 
object files and make the end user link them


Re: Variable cannot be read at compile time.

2017-12-07 Thread Ali Çehreli via Digitalmars-d-learn

On 12/07/2017 04:45 PM, aliak wrote:

Hi, I'm having a bit a trouble doing some compile time parsing. This works:

immutable str = "he-.llo-the.re";
immutable separators = "-.";
enum a = str.splitter(separators).array;

But this does not:

enum b = str.splitter!(a => separators.canFind(a)).array;

The error is: cannot deduce function from argument types !((a) => 
separators.canFind(a))(immutable(string))


And this does:

enum c = str.splitter!(a => a == a).array;

And this does not:

enum d = str.splitter!(a => a == separators).array;

What am I missing?

Thanks!




Most work with 2.076 for me. 'd' does not work because while str.front 
is dchar, separators is a string, so 'a == separators' does not compile:


import std.stdio;
import std.algorithm;
import std.range;

void main() {
immutable str = "he-.llo-the.re";
immutable separators = "-.";

enum a = str.splitter(separators).array;
enum b = str.splitter!(a => separators.canFind(a)).array;
enum c = str.splitter!(a => a == a).array;
// enum d = str.splitter!(a => a == separators).array;

writeln(a);
writeln(b);
writeln(c);
}

["he", "llo-the.re"]
["he", "", "llo", "the", "re"]
["", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]

Ali



Variable cannot be read at compile time.

2017-12-07 Thread aliak via Digitalmars-d-learn
Hi, I'm having a bit a trouble doing some compile time parsing. 
This works:


immutable str = "he-.llo-the.re";
immutable separators = "-.";
enum a = str.splitter(separators).array;

But this does not:

enum b = str.splitter!(a => separators.canFind(a)).array;

The error is: cannot deduce function from argument types !((a) => 
separators.canFind(a))(immutable(string))


And this does:

enum c = str.splitter!(a => a == a).array;

And this does not:

enum d = str.splitter!(a => a == separators).array;

What am I missing?

Thanks!




Re: Any derelict fmod users on Linux out there?

2017-12-07 Thread Mike Parker via Digitalmars-d-learn

On Thursday, 7 December 2017 at 22:57:20 UTC, WhatMeWorry wrote:
I've tried debugging this for hours to no avail. It works on 
Windows and Mac fine. But I'm running Antergos Linux (very much 
like Arch) and it keeps failing at the System Init line. The 
code is pretty much a copy of the example of derelict fmod on 
github.  I have no idea what the "bindings" number below refers 
to?




My guess it's the result of this pull:

https://github.com/Extrawurst/DerelictFmod/pull/3

Though, I would expect it to break on Mac as well.


Any derelict fmod users on Linux out there?

2017-12-07 Thread WhatMeWorry via Digitalmars-d-learn
I've tried debugging this for hours to no avail. It works on 
Windows and Mac fine. But I'm running Antergos Linux (very much 
like Arch) and it keeps failing at the System Init line. The code 
is pretty much a copy of the example of derelict fmod on github.  
I have no idea what the "bindings" number below refers to?


=== Code snippet 
==


auto res = FMOD_System_Create(&fmod);  // works

printVersion();
printDrivers();

FMOD_RESULT res2 = FMOD_System_Init(fmod, 32, FMOD_INIT_NORMAL, 
null);


checkForErrors(res2, "After call to FMOD_System_Init", true);


=== Output 
=


FMOD library loaded
fmod version: 69633 (bindings: 67335)
fmod drivers: 1
fmod driver [0]: (48000,3,2,'Built-in Audio Analog Stereo')
i = 0
sampleRate = 48000
speakermode = 3
speakermodeChannels = 2
name = Built-in Audio Analog Stereo

FMOD error An error occurred that wasn't supposed to.  Contact 
support.



My run time libraries consist of the very latest from the fmod 
web site.

libfmod.so
libfmod.so.10
libfmod.so.10.1
libmodstudio.so
libmodstudio.so.10
libmodstudio.so.10.1










Re: Binary serialization of a struct

2017-12-07 Thread kdevel via Digitalmars-d-learn

On Tuesday, 19 September 2017 at 06:32:52 UTC, Nordlöw wrote:
I want something straight forward without allot of plumbing on 
my end.


https://github.com/msgpack/msgpack-d


I can't unittest my 32-bit code:

$ MODEL=32 make -f posix.mak unittest
[...]
src/msgpack/packer.d(1139): Error: function 
core.stdc.stdlib.malloc (uint size) is not callable using 
argument types (ulong)





Re: Does dmd not always compile all of the source code?

2017-12-07 Thread user1234 via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 19:19:09 UTC, A Guy With a 
Question wrote:
On Wednesday, 6 December 2017 at 18:09:45 UTC, Steven 
Schveighoffer wrote:

On 12/6/17 12:17 PM, Steven Schveighoffer wrote:

So why wouldn't the compiler fail? Because it has no idea yet 
what you mean by Nullable. It doesn't even know if Nullable 
will be available or not. You could even import Nullable, but 
Nullable!T may be an error.


To give an example of why the compiler waits until 
instantiation:


class C(T) : T
{
   void foo() { doesthisexist(); }
}

class D { void doesthisexist(); }

auto x = new C!D; // OK
auto y = new C!Object: // fail

-Steve


It also doesn't parse or do semantic checks on unit tests 
unless you add the flag...apparently.


This compiles...

unittest
{
WHY DOESNT THE COMPILER FIND A PROBLEM HERE!?
}

It seems D's fast compile times are achieved by skipping 
semantic checking and even parsing when it doesn't feel it's 
needed. I strongly disagree with this decision. This could 
leave complex dormant time bombs that break builds unexpectedly 
and even accidentally.


That's why measuring the level of coverage obtained by the 
unittests is important.
It's not just about the templates, standard if conditions that 
are never tested can also be time bombs, standard functions that 
are never tested can also be time bombs. Even more pernicious in 
a way.


Re: Sort characters in string

2017-12-07 Thread Patrick Schluter via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 15:12:22 UTC, Steven 
Schveighoffer wrote:

On 12/6/17 4:34 AM, Ola Fosheim Grøstad wrote:
On Wednesday, 6 December 2017 at 09:24:33 UTC, Jonathan M 
Davis wrote:
UTF-32 on the other hand is guaranteed to have a code unit be 
a full code point.


I don't think the standard says that? Isn't this only because 
the current set is small enough to fit? So this may change as 
Unicode grows?





The current unicode encoding has 2 million different code 
points.


2,097,152 possible codepoints. As of [Unicode 10] only 136,690 
codepoints have been assigned.



I'd say we'll all be dead and so will our great great
great grandchildren by the time unicode amasses more than 2 
billion codepoints :)


So there's enough time even before the current range is even 
filled.




Also, UTF8 has been standardized to only have up to 4 code 
units per code point. The encoding scheme allows more, but the 
standard restricts it.




[Unicode 10]: http://www.unicode.org/versions/Unicode10.0.0/


Re: Sort characters in string

2017-12-07 Thread Patrick Schluter via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 09:34:48 UTC, Ola Fosheim 
Grøstad wrote:
On Wednesday, 6 December 2017 at 09:24:33 UTC, Jonathan M Davis 
wrote:
UTF-32 on the other hand is guaranteed to have a code unit be 
a full code point.


I don't think the standard says that? Isn't this only because 
the current set is small enough to fit? So this may change as 
Unicode grows?


No. Unicode uses only 21 bits and it is very unlikely to change 
anytime soon as barely 17 are really used. This means the current 
range can be grown by more than 16 times what it is now. So 
definitely, one UTF-32 codeunit is guaranted to hold any 
codepoint, forever.





Re: Sort characters in string

2017-12-07 Thread Patrick Schluter via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 09:24:33 UTC, Jonathan M Davis 
wrote:
a full code point (IIRC, 1 - 6 code units for UTF-8 and 1 - 2 
for UTF-16),


YDNRC, 1 - 4 code units for UTF-8. Unicode is defined only up to 
U+10. Everything above is illegal.


Open Scene Graph For D?

2017-12-07 Thread Tofu ninja via Digitalmars-d-learn
Is there a binding for it? Just a question, trying to convince 
people at work to use D and that is something they asked about.


Re: Debugging shared libs on windows

2017-12-07 Thread Tofu ninja via Digitalmars-d-learn

On Wednesday, 6 December 2017 at 22:59:17 UTC, user1234 wrote:

On Wednesday, 6 December 2017 at 21:17:55 UTC, Tofu ninja wrote:
On Wednesday, 6 December 2017 at 21:12:20 UTC, Tofu ninja 
wrote:
I am compiling with -m64 -shared -debug -g and a .pdb is 
generated but visual studio says the dll was not compiled 
with debug information, am I missing something or is this not 
supported?


DMD32 D Compiler v2.076.0


Actually never mind, -gf worked


what is -gf ? it's not documented here 
https://dlang.org/dmd-windows.html#switches


dmd has this in the help
-gf  emit debug info for all referenced types

I dont know why that made it work, I feel like -g should have 
still made it at least recognizable for a debugger but it didn't 
think it was compiled with debug info. My suspicion is it 
compiled debug info for the import .lib but not for the DLL 
itself and -gf forced it to do the dll too. But I haven't 
confirmed that.


Re: package modules and how to generate a shared library plus .di file (I)

2017-12-07 Thread kdevel via Digitalmars-d-learn

On Thursday, 7 December 2017 at 17:58:38 UTC, ag0aep6g wrote:

On 12/07/2017 06:53 PM, kdevel wrote:
Does that mean, that though the code is bundled in one library 
(libmymod.a) for the prototypes one has as many .di files as 
there

were source files?


yes


Gosh! So in my example I need the following structure

   libmymod.a
   main.d
   mymod/
  bar.di
  foo.di
  package.d   (note the extension!)

in order to get

   $ dmd main.d -L-L. -L-lmymod

working.


Re: package modules and how to generate a shared library plus .di file (I)

2017-12-07 Thread Adam D. Ruppe via Digitalmars-d-learn

On Thursday, 7 December 2017 at 17:53:25 UTC, kdevel wrote:
Does that mean, that though the code is bundled in one library 
(libmymod.a) for the prototypes one has as many .di files as 
there

were source files?


Unless those files were internal, yes. Public names in modules 
are... well, public. They are part of the interface, and that 
includes the module name (D uses module names for namespace 
disambiguation and it is part of the link mangle too).


You might want to look at the dmd2/src/druntime folder in the dmd 
zip. Contrast the import directory to the src directory.


You'll find all public modules are in both, but some internal 
implementations are in src only (and the compiled library) but 
not the import interface dir.


Re: package modules and how to generate a shared library plus .di file (I)

2017-12-07 Thread ag0aep6g via Digitalmars-d-learn

On 12/07/2017 06:53 PM, kdevel wrote:
Does that mean, that though the code is bundled in 
one library (libmymod.a) for the prototypes one has as many .di files as 
there

were source files?


yes


Re: Template for Multiple Function Parameters

2017-12-07 Thread Adam D. Ruppe via Digitalmars-d-learn

On Thursday, 7 December 2017 at 17:52:30 UTC, Vino wrote:


auto mTemplate(T n) (T n) {
return tuple (N);



auto mTemplate(T...)(T n) {
   return tuple(n);
}

see https://dlang.org/spec/template.html#variadic-templates


Template for Multiple Function Parameters

2017-12-07 Thread Vino via Digitalmars-d-learn

Hi,

  Request your help, on how to define N arguments, example in the 
below code we are stating the the function mTemplate has to 
receive 3 parameters so we define as "mTemplate(T1, T2, T3) (T1 
Name, T2 USize, T3 ISize)", so rather than defining 3 (T1,T2,T3) 
would it be possible to define like (T n) meaning that the 
function can receive any number of parameters.


import std.stdio: writeln;
import std.typecons: tuple;

auto mTemplate(T1, T2, T3) (T1 Name, T2 USize, T3 ISize) {
return tuple (Name, USize, ISize);
}
void main () {
string Name = "Test";
ulong USize = 1024;
int ISize = 10;
writeln(mTemplate(Name, USize, ISize)[]);
}

Something similar as below:

auto mTemplate(T n) (T n) {
return tuple (N);
}
void main () {
string Name = "Test";
ulong USize = 1024;
int ISize = 10;
writeln(mTemplate(Name)[]);
writeln(mTemplate(Name, USize)[]);
writeln(mTemplate(Name, USize, ISize)[]);
}


From,
Vino.B



Re: package modules and how to generate a shared library plus .di file (I)

2017-12-07 Thread kdevel via Digitalmars-d-learn
On Thursday, 7 December 2017 at 17:36:22 UTC, Neia Neutuladh 
wrote:

If you have a source tree like:

pierce/
  db/
core.d
  controllers/
feed.d

then feed.d can have `import pierce.db.core;` instead of people 
being confused about how to refer to the parent directory in a 
relative imports style.


The tradeoff is that you have to type sometimes as many as 
twelve extra characters in a handful of lines of code.


Okay. So I have now

   mymod/
  foo.d
  bar.d

Now I compile the library

   $ dmd -lib -oflibmymod.a mymod/foo.d mymod/bar.d

now I want to replace all the source code by a single .di file 
containing the protoypes. I know that dmd -H generates protoypes. 
When I use


   $ dmd -H -lib -oflibmymod.a mymod/foo.d mymod/bar.d

I get

   bar.di
   foo.di

at the top level dir. Does that mean, that though the code is 
bundled in one library (libmymod.a) for the prototypes one has as 
many .di files as there

were source files?






Re: package modules and how to generate a shared library plus .di file (I)

2017-12-07 Thread Neia Neutuladh via Digitalmars-d-learn

On Thursday, 7 December 2017 at 16:39:14 UTC, kdevel wrote:

But why do I have to use the prefix "mymod.:" in the
library case?


If you have an editor open with ten tabs pointing to different 
files in your source tree, all your imports are uniform -- you 
don't have to step back and consider where the specific file 
you're editing is and calculate relative import paths.


You always import a given module with the exact same code. If you 
copy and paste code between two modules and that contains an 
import statement, it just works.


If you decide to move a module to a different package, you need 
to change its module name, move it on disk, and update the stuff 
that imports it. You don't have to update every import it does.


If you have a source tree like:

pierce/
  db/
core.d
  controllers/
feed.d

then feed.d can have `import pierce.db.core;` instead of people 
being confused about how to refer to the parent directory in a 
relative imports style.


The tradeoff is that you have to type sometimes as many as twelve 
extra characters in a handful of lines of code.


Re: Does dmd not always compile all of the source code?

2017-12-07 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 16:07:41 UTC, A Guy With a 
Question wrote:

Does dmd not compile all source code?


It doesn't. I like to build with a few different options to 
explicitly test (e.g. build for Windows and Linux and -m32 and 
-m64 to ensure those all  exercised) and for templates, do a 
-unittest that actually runs it - e.g. instantiate Array!int - to 
make sure that works and compile with -unittest every so often 
too. Might also do a `__traits(compiles` or static assert on it 
too.


Others have explained why this is, but this is a simple way to 
ensure it compiles at least in some cases to catch typos like 
this.


Another worry btw: the opDispatch feature will just say `no such 
property` if it fails to compile its innards. A test might also 
want to call it explicitly to force error messages.


Re: package modules and how to generate a shared library plus .di file (I)

2017-12-07 Thread Andrea Fontana via Digitalmars-d-learn

On Thursday, 7 December 2017 at 16:39:14 UTC, kdevel wrote:
Then (*) works as expected. But why do I have to use the prefix 
"mymod.:" in the

library case?


Because module names are not relative to file path, but to import 
path / compile path afaik.


package modules and how to generate a shared library plus .di file (I)

2017-12-07 Thread kdevel via Digitalmars-d-learn
Given the functions void foo() and void bar() in their source 
files mymod/foo.d and mymod/bar.d. Also I have a


mymod/package.d
```
module mymod;

public import foo : foo;
public import bar : bar;
```

and a client to the library:

main.d
```
import mymod;

void main ()
{
   foo;
   bar;
}
```

It compiles fine with

   $ dmd main.d mymod/foo.d mymod/bar.d

Now I want to link against libmymod.a. First I prepare the 
library:


   $ dmd -lib -oflibmymod.a mymod/foo.d mymod/bar.d

and then

   $ dmd main.d -L-L. -L-lmymod 
(*)
   mymod/package.d(3): Error: module foo is in file 'foo.d' which 
cannot be read

   import path[0] = .../linux/bin64/../../src/phobos
   import path[1] = .../linux/bin64/../../src/druntime/import

In order to make that Error go away I have to change

package.d
```
module mymod;

public import mymod.foo : foo;
public import mymod.bar : bar;
```

Then (*) works as expected. But why do I have to use the prefix 
"mymod.:" in the

library case?


Re: Problem getting Cimgui to work

2017-12-07 Thread Thomas via Digitalmars-d-learn


So the steps should be:

checkout imgui 1.50
checkout cimgui 1.50
Build both
Put them on your system library path

Then you should be set to use DerelictIMGUI without the need to 
modify its package recipe.



Thank you for your very very good description what was going on 
and how everything relate together! I will watch closely the 
version numbers from now on :-)


Best wishes!


Re: Parsing a string from stdin using formattedRead

2017-12-07 Thread Adam D. Ruppe via Digitalmars-d-learn

On Wednesday, 6 December 2017 at 18:47:03 UTC, Mark wrote:

formattedRead(readln(), "%s %s", first_name, last_name);


You could write a little wrapper function to do that

uint myformattedRead (R, Char, S...)(R r, const(Char)[] fmt, auto 
ref S args) {

formattedRead(r, fmt, args);
}


It just strips the ref off of the input string but otherwise 
forwards the same thing.


The reason it is ref tho btw is that that allows it to continue 
off a particular input; you can do like


string s;
formattedRead(s, )
formattedRead(s, ) // this one picks up where the last one 
left off


Re: building git druntime - range violation in extendedPathThen

2017-12-07 Thread Nick Treleaven via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 17:11:49 UTC, Nick Treleaven 
wrote:
0x005482C2 in nothrow void* 
ddmd.root.filename.extendedPathThen!(ddmd.root.file.File.read().__lambda1).extendedPathThen(const(char*)) at C:\git\dmd\src\ddmd\root\filename.d(834)

0x005480E8 in File at C:\git\dmd\src\ddmd\root\file.d(198)


For now this workaround lets me compile druntime:

--- a/src/ddmd/root/file.d
+++ b/src/ddmd/root/file.d
@@ -193,6 +193,8 @@ nothrow:

 // work around Windows file path length limitation
 // (see documentation for extendedPathThen).
+if (!name[0])
+return true;
 HANDLE h = name.extendedPathThen!
 (p => CreateFileW(&p[0],
   GENERIC_READ,



Re: GUI program on Mac OS in D?

2017-12-07 Thread Guillaume Piolat via Digitalmars-d-learn
On Thursday, 7 December 2017 at 12:18:21 UTC, Guillaume Piolat 
wrote:


You can easily make a DUB frontend to do that, for example 
https://github.com/AuburnSounds/Dplug/tree/master/tools/dplug-build


And it might be cleaner to do this as a post-build step.


Re: GUI program on Mac OS in D?

2017-12-07 Thread Guillaume Piolat via Digitalmars-d-learn

On Wednesday, 6 December 2017 at 16:50:10 UTC, mrphobby wrote:


Also, is there any support for creating macOS application 
bundles?


[1] https://dlang.org/spec/objc_interface.html
[2] https://wiki.dlang.org/DIP43


You can easily make a DUB frontend to do that, for example 
https://github.com/AuburnSounds/Dplug/tree/master/tools/dplug-build


(you'll find some code that generates Mac bundles in there, with 
pretty minimal Info.plist)


Re: Directory Size

2017-12-07 Thread Vino via Digitalmars-d-learn

On Thursday, 7 December 2017 at 09:04:19 UTC, Vino wrote:
On Wednesday, 6 December 2017 at 15:04:55 UTC, Andrea Fontana 
wrote:

On Wednesday, 6 December 2017 at 14:49:48 UTC, Vino wrote:


[...]


Just use Array! constructor.

auto mSize () {
string FFs = "/home/andrea/Scaricati";

   return
   Array!(Tuple!(string,string))(
   dirEntries(FFs, SpanMode.shallow)
   .filter!(a => a.isDir)
   .map!(a => tuple(a.name, 
a.dirEntries(SpanMode.depth).filter!(a=>a.isFile).map!(a => 
a.size).sum))

   .filter!(a => a[1] > 1024*1024*30)
   .map!(a => tuple(a[0], a[1].to!string))
   );
}


Hi Andrea,

  I test your code, initially it error ed out stating "patch 
does not exist", the reason for this error is that the length 
of the path is more than 256 , so added the UNC path to the 
code as below.


auto mSize () {
string FFs = "C:\Temp\BACKUP";
ulong SGb = 1024 * 1024;
int SizeDir = 10;

return Array!(Tuple!(string,real))(
 dirEntries(join(["?\\", FFs]), SpanMode.shallow).filter!(a 
=> a.isDir)
 .map!(a => tuple(a.name, 
a.dirEntries(SpanMode.depth).filter!(a=>a.isFile)

 .map!(a => a.size).sum)).filter!(a => a[1] >  (SGb * SizeDir))
 .map!(a => tuple(a[0], ((a[1].to!real)/ SGb ;
}

The output of the code is as below
\\?\C:\Temp\BACKUP\dir1 34.90
\\?\C:\Temp\BACKUP\dir2 36.18

So how do we print the output without UNC path
C:\Temp\BACKUP\dir1 34.90
C:\Temp\BACKUP\dir2 36.18

From,
Vino.B


Hi Andrea,

 Was able to find a solution to the above issue by adding the 
replace function as below, the the code is working as expected, 
is there any chance of using parallel function as the file system 
contains about 500+ folders and the size of each folder ranges 
from 5GB - 500 GB so the run time of the above code is about an 2 
hours.


.map!(a => tuple(a[0].replace(",\\?\", ""), ((a[1].to!real)/ SGb 
;


From,
Vino.B


Re: What is "stringImportPaths"

2017-12-07 Thread Jacob Carlborg via Digitalmars-d-learn

On 2017-12-06 20:05, mrphobby wrote:
Can anyone explain what "stringImportPaths" is? I have seen this being 
used in dub.json files and I think I kind of know what it does, but I 
haven't been able to find a clear explanation in any documentation of 
what it does. It does not look like anything I'm familiar with from 
other languages.


I understand it can be used for resources but I have seen it being used 
with both text files and binary files so I'm a bit confused. The 
documentation says I can import "whatever", but that feels a bit weird 
since importing is a construct used for importing symbols, right?


There are two kinds of language constructs that uses the "import" 
keyword. One is the "Import Declaration" [1] which is the most common 
one and is used to import other symbols. The other language construct is 
the "Import Expression" [2], which is used to read a file at compile 
time and put its content into a string literal in your source code.


Anything specified to the "stringImportPaths" build setting will be sent 
to the compiler with the -J flag.


[1] https://dlang.org/spec/module.html#ImportDeclaration
[2] https://dlang.org/spec/expression.html#import_expressions

--
/Jacob Carlborg


Re: GUI program on Mac OS in D?

2017-12-07 Thread Jacob Carlborg via Digitalmars-d-learn

On 2017-12-06 17:50, mrphobby wrote:

I'm also interested in making native macOS apps. I have a lot of 
experience in Objective-C but I'm new at D. I'm a bit confused at what 
documentation to look at. In [1] I get the impression that support for 
creating instances is very rudimentary, but in [2] it looks much better 
with constructors mapped with @selector. What level of support is there 
in the latest DMD compiler?


The latest DMD compiler only supports what's in the official 
documentation, i.e. [1]. What's documented in DIP43 [2] (except anything 
marked with "unimplemented") is what's been implemented in one of my 
forks. I'm working on adding what's in my fork piece by piece to upstream.



Also, is there any support for creating macOS application bundles?


No, there are currently no plans for that. As far as I understand the 
Objective-C compiler will not to this either. When using Objective-C I 
think either Xcode or some other tool is creating the bundle. Note that 
a bundle is just a directory with a specific structure, which can easily 
be created without any special tools.


[1] https://dlang.org/spec/objc_interface.html
[2] https://wiki.dlang.org/DIP43

--
/Jacob Carlborg


Re: Sort characters in string

2017-12-07 Thread Mengu via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 12:43:09 UTC, Fredrik Boulund 
wrote:

On Wednesday, 6 December 2017 at 10:42:31 UTC, Dgame wrote:



Or you simply do

writeln("longword".array.sort);



This is so strange. I was dead sure I tried that but it failed 
for some reason. But after trying it just now it also seems to 
work just fine. Thanks! :)


if you're like me, you probably forgot an import :)


Re: Directory Size

2017-12-07 Thread Vino via Digitalmars-d-learn
On Wednesday, 6 December 2017 at 15:04:55 UTC, Andrea Fontana 
wrote:

On Wednesday, 6 December 2017 at 14:49:48 UTC, Vino wrote:


Hi Andrea,

  Thank you very much, as your code is pretty good for our 
scenario, just one request, the above is a part of our main 
code where we have many such sub code and all of our sub code 
use the container array(std.container.array) rather than 
standard array(std.array), so can you please guide me on how 
to implement the same code using the container array.


From,
Vino.B.


Just use Array! constructor.

auto mSize () {
string FFs = "/home/andrea/Scaricati";

   return
   Array!(Tuple!(string,string))(
   dirEntries(FFs, SpanMode.shallow)
   .filter!(a => a.isDir)
   .map!(a => tuple(a.name, 
a.dirEntries(SpanMode.depth).filter!(a=>a.isFile).map!(a => 
a.size).sum))

   .filter!(a => a[1] > 1024*1024*30)
   .map!(a => tuple(a[0], a[1].to!string))
   );
}


Hi Andrea,

  I test your code, initially it error ed out stating "patch does 
not exist", the reason for this error is that the length of the 
path is more than 256 , so added the UNC path to the code as 
below.


auto mSize () {
string FFs = "C:\Temp\BACKUP";
ulong SGb = 1024 * 1024;
int SizeDir = 10;

return Array!(Tuple!(string,real))(
 dirEntries(join(["?\\", FFs]), SpanMode.shallow).filter!(a 
=> a.isDir)
 .map!(a => tuple(a.name, 
a.dirEntries(SpanMode.depth).filter!(a=>a.isFile)

 .map!(a => a.size).sum)).filter!(a => a[1] >  (SGb * SizeDir))
 .map!(a => tuple(a[0], ((a[1].to!real)/ SGb ;
}

The output of the code is as below
\\?\C:\Temp\BACKUP\dir1 34.90
\\?\C:\Temp\BACKUP\dir2 36.18

So how do we print the output without UNC path
C:\Temp\BACKUP\dir1 34.90
C:\Temp\BACKUP\dir2 36.18

From,
Vino.B