Debugging a druntime issue found by AutoTester

2017-12-11 Thread Ali Çehreli via Digitalmars-d-learn
The automatic tests for a PR failed for a target that I could not test 
myself: 32-bit build on Darwin_64_32.



https://auto-tester.puremagic.com/show-run.ghtml?projectid=1=2940199=20802787=true

Testing attach_detach
timelimit -t 10 ./generated/osx/debug/32/attach_detach
attach_detach(32762,0xb0103000) malloc: *** error for object 0x1000: 
pointer being freed was not allocated

*** set a breakpoint in malloc_error_break to debug
make[2]: *** [generated/osx/debug/32/attach_detach.done] Error 134
make[1]: *** [test/thread/.run] Error 2
make: *** [unittest-debug] Error 2

How can I reproduce the issue perhaps on my Ubuntu-based 64-bit laptop? 
I'm hoping that the problem will be obvious if I can build a 32-bit 
target and "set a breakpoint in malloc_error_break to debug".


I tried to build a 32-bit dmd on my system but failed with dependency 
issues. Is the following right way?


$ MODEL=32 make -f posix.mak -j8 AUTO_BOOTSTRAP=1
[...]
/usr/bin/ld: skipping incompatible 
/usr/lib/gcc/x86_64-linux-gnu/5/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible 
/usr/lib/gcc/x86_64-linux-gnu/5/libstdc++.a when searching for -lstdc++

/usr/bin/ld: cannot find -lstdc++
collect2: error: ld returned 1 exit status

Ali


Re: Static array as immutable

2017-12-11 Thread Radu via Digitalmars-d-learn

On Tuesday, 12 December 2017 at 07:33:47 UTC, Ivan Trombley wrote:

Is there some way that I can make this array immutable?

  static float[256] ga = void;
  static foreach (i; 0 .. 256)
  ga[i] = (i / 255.0f) ^^ (1 / 2.2f);


Check
https://dlang.org/phobos/std_exception.html#assumeUnique


Static array as immutable

2017-12-11 Thread Ivan Trombley via Digitalmars-d-learn

Is there some way that I can make this array immutable?

  static float[256] ga = void;
  static foreach (i; 0 .. 256)
  ga[i] = (i / 255.0f) ^^ (1 / 2.2f);



Re: OT (Was: Re: What's the proper way to use std.getopt?)

2017-12-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, December 11, 2017 15:38:44 H. S. Teoh via Digitalmars-d-learn 
wrote:
> On Mon, Dec 11, 2017 at 11:35:53PM +, Seb via Digitalmars-d-learn
> wrote: [...]
>
> > D style would be to use sth. like this (instead of try/catch):
> >
> > ```
> > scope(failure) {
> >
> >   e.msg.writeln;
> >   1.exit;
> >
> > }
> > ```
>
> Frankly, much as I love UFCS syntax, I think this is taking it a little
> too far.  Maybe I'm just old-fashioned, but I still find `exit(1)` much
> more readable than `1.exit`. Ditto for the writeln.

Clearly, there's quite a range of what folks like or find acceptable.
Personally, I never drop the parens unless it makes sense to treat the
function like a property, so even if I were doing something like Seb here,
it would be

e.msg.writeln();
1.exit();

but like you, I wouldn't use UFCS here. I don't know exactly what the line
is for me though; some functions just don't feel right with UFCS, and others
are perfectly fine. I think that part of it is probably whether the function
returns. I'm unlikely to use UFCS if the function is void like these are.
For whatever reason, using UFCS with something like writeln or exit just
seems really wrong to me. But then again, I also think that it feels really
wrong to do something like 42.msecs or 42.msecs(), and that _does_ return a
value. Maybe it's because it feels like a constructor to me, and you don't
use UFCS with constructors. I don't know. I don't know how logical or
consistent my reasoning is with when to use UFCS, since I've never sat down
and studied it. Sometimes, it feels perfectly reasonable, and other times,
it just feels really wrong.

Either way, clearly, different folks have a different level of tolerance or
liking for UFCS in various circumstances.

- Jonathan M Davis



Re: Why is there no std.stream anymore?

2017-12-11 Thread codephantom via Digitalmars-d-learn

On Tuesday, 12 December 2017 at 02:15:13 UTC, codephantom wrote:


just playing around with this



also...in case you only want to read n bytes..

// ---

module test;

import std.stdio, std.file, std.exception;
import std.datetime.stopwatch;


void main()
{
string filename = "test.txt";  // a text file
//string filename = "test.exe"; // a binary file

enforce(filename.exists, "Umm..that file does not exist!");

auto file = File(filename, "r");
ubyte[] buf;

import std.datetime : MonoTime;
auto t2 = MonoTime.currTime;

// just read the first n bytes.
int bytesToRead = 4; // change this n
int bufCount;
while ( !file.eof() && bufCount < bytesToRead )
{
buf = file.rawRead(new ubyte[1]);

if(!file.eof())
{
process(cast(char)(buf[0]));
bufCount++;
}
}


writeln("-");
writeln("this took : ", MonoTime.currTime - t2);
writeln("-");
writeln();

return;
}

void process(char someChar)
{
import std.ascii : isPrintable;

if( isPrintable(someChar) )
writeln("found a printable character: ", someChar);
else
writeln("found a non printable character");

}
// ---



Re: Why is there no std.stream anymore?

2017-12-11 Thread codephantom via Digitalmars-d-learn
On Monday, 11 December 2017 at 20:51:41 UTC, Jordi Gutiérrez 
Hermoso wrote:
I'd like to read from a file, one byte at a time, without 
loading the whole file in memory.




just playing around with this

// 

module test;

import std.stdio, std.file, std.exception;

void main()
{
string filename = "test.txt";
enforce(filename.exists, "Umm..that file does not exist!");

auto file = File(filename, "r");
char[] charBuf;

while (!file.eof())
{
charBuf = file.rawRead(new char[1]);

if(!file.eof())
process(cast(char)(charBuf[0]));
}

return;
}

void process(char someChar)
{
import std.ascii : isPrintable;

if( isPrintable(someChar) )
writeln("found a printable character: ", someChar);
else
writeln("found a non printable character");

}
// 



Re: Open Scene Graph For D?

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

On Thursday, 7 December 2017 at 19:30:13 UTC, Tofu ninja wrote:
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.


Guess not


Re: Clarify "Starting as a Contributor" document

2017-12-11 Thread Seb via Digitalmars-d-learn

On Monday, 11 December 2017 at 14:13:41 UTC, Dukc wrote:

On Sunday, 10 December 2017 at 08:18:17 UTC, Ali Çehreli wrote:

This page is very good:

  https://wiki.dlang.org/Starting_as_a_Contributor

I need clarifications


Another oddity: Someone has apparently made DRuntime build to 
use ../dmd/generated/windows/32/dmd instead of the "system" dmd 
recently. Perhaps the idea here is that I do not have to go 
replacing my system dmd anymore.


Yes, that someone would be myself.

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

It's part of a long-lasting effort to get rid of `src/dmd`,
s.t. we can rename the `ddmd` package to `dmd`.
See:

https://github.com/dlang/dmd/pull/7135

But the problem is that when I build dmd, for some reason, the 
build file deletes that generated dmd at the end. Can be 
resolved by moving the dmd manually to that directory, but that 
is not explained at the web page. Should we tweak dmd to build 
into the generated directory instead of working directory, or 
tweak DRuntime to use ../dmd/src/dmd instead? Or am I missing 
something?


As explained, it's a huge effort to switch from ../src/dmd to to 
../generated, because in the meantime none of the existing CIs 
and integrations etc. are allowed to break.
However, it sounds weird that the generated dmd executable get 
removed.

How do you build dmd and what are your system details?


Re: What's the proper way to use std.getopt?

2017-12-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 11 December 2017 at 20:58:25 UTC, Jordi Gutiérrez 
Hermoso wrote:
I don't quite understand what to do if getopt throws. I would 
have hoped for something like


I might have already said this to you on IRC but the way I'd do 
it (if you must do this) is:


void main(string[] args) {
int arg1;
string arg2;

bool getoptions(string[] args) {
   auto result = getopt(args, "opt1", "docstring 1", , 
"opt2", "docstring 2", );

   if(result.helpWanted)
 defaultGetoptPrinter("Some information about the 
program.", result.options);

   return result.helpWanted;
}

try {
   if(getoptions(args))
return; // it just printed help
} catch(GetOptException e) {
   writeln(e.msg);
   getoptions(["--help"]);
   return;
}

/* rest of your program */
}



Even though, I think printing the whole help output on any 
exception is likely to be fairly annoying since it obscures the 
actual error message.


Re: Clarify "Starting as a Contributor" document

2017-12-11 Thread Seb via Digitalmars-d-learn

On Monday, 11 December 2017 at 06:43:46 UTC, Ali Çehreli wrote:

On 12/10/2017 12:36 AM, Seb wrote:

> [...]
is no harm
> [...]

Thanks. I don't care anymore. :)

>> [...]
should have
>> [...]
a comment
>> [...]
necessary
>> [...]
message should
> [...]
second part
> [...]
opened a PR and
> [...]
message.

So, the last sentence should be something like "The rebase 
allows you an extra opportunity to mention the Bugzilla issue 
if your original commit did not already mention it."?


Yes.


> [...]
commit message.
> [...]

It was helpful but not for that specific question.

> [...]

There is the following part:


First, fork the github repository or repositories you'd like to 
contribute to (dmd, druntime, phobos etc) by navigating to 
their respective pages on github.com and clicking "Fork". Then, 
set up your local git repository to reflect that. For example, 
consider you want to contribute to phobos and have forked it. 
Then run these commands:


  cd ~/code/phobos
  git remote add myfork https://github.com/username/phobos.git
  git remote update


That sequence does not work because apparently code/phobos must 
already be a git repo but the text does not explain where it 
comes from. So, I added three commands to the sequence and it 
seemed to work:


  mkdir -p ~/code/phobos   # <-- 1
  git init # <-- 2
  cd ~/code/phobos
  git remote add myfork https://github.com//phobos.git
  git remote update
  git pull myfork master   # <-- 3

Was I correct?


Well, the typical behavior is to set your fork as origin and 
upstream as `upstream`.

Also instead of git init etc., you can do a git clone directly.

Of course, it would be better to explain how one gains 
code/phobos.



That's what the building from source section should do:

https://wiki.dlang.org/Starting_as_a_Contributor#Building_from_source

However, I reworked the guide a bit to allow both options.

I think that section should include setting up both the 
upstream repo and the myfork repo. I think a contributor would 
regularly be using both.


Agreed. I tried to improve the contribution guide today.
Did my changes help or are you still missing something or isn't 
fully explained?



Ali

P.S. As I mentioned recently on this newsgroup, the general 
lack of information on the two repos, "upstream" and "personal 
fork", were the most detrimental to my understanding of git 
workflows. We do that in our document but I think setting up 
"upstream" should be a part of the command sequence above.


I added this to the document. Thanks for pointing it out!


OT (Was: Re: What's the proper way to use std.getopt?)

2017-12-11 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Dec 11, 2017 at 11:35:53PM +, Seb via Digitalmars-d-learn wrote:
[...]
> D style would be to use sth. like this (instead of try/catch):
> 
> ```
> scope(failure) {
>   e.msg.writeln;
>   1.exit;
> }
> ```

Frankly, much as I love UFCS syntax, I think this is taking it a little
too far.  Maybe I'm just old-fashioned, but I still find `exit(1)` much
more readable than `1.exit`. Ditto for the writeln.

scope(failure), OTOH, rawkz. :-P


T

-- 
Don't drink and derive. Alcohol and algebra don't mix.


Re: What's the proper way to use std.getopt?

2017-12-11 Thread Jordi Gutiérrez Hermoso via Digitalmars-d-learn

On Monday, 11 December 2017 at 21:24:41 UTC, Mike Wey wrote:


try
{
auto helpInformation = getopt(
args,
"input|i", "The input", ,
"output|o", "The output", 
);

if (helpInformation.helpWanted)
{
defaultGetoptPrinter("Description", helpInformation.options);
exit(0);
}
}
catch (GetOptException e)
{
writeln(e.msg);
exit(1);
}


But I would like to show the help docstring when processing the 
exception. It's pretty standard behaviour. If you give a program 
bad arguments, it just spits out a docstring of all options and 
what each does. Can this be achieved?





Re: Get pointer or reference of an element in Array(struct)

2017-12-11 Thread Arun Chandrasekaran via Digitalmars-d-learn
On Saturday, 9 December 2017 at 19:26:26 UTC, David Nadlinger 
wrote:

but "free" references don't exist in the language.


To the point! Thanks!


Re: What's the proper way to use std.getopt?

2017-12-11 Thread Seb via Digitalmars-d-learn

On Monday, 11 December 2017 at 21:24:41 UTC, Mike Wey wrote:

On 11-12-17 21:58, Jordi Gutiérrez Hermoso wrote:

[...]



I would use something like this, print the help information for 
--help, print an error for invalid arguments:



```
try
{
auto helpInformation = getopt(
args,
"input|i", "The input", ,
"output|o", "The output", 
);

if (helpInformation.helpWanted)
{
defaultGetoptPrinter("Description", helpInformation.options);
exit(0);
}
}
catch (GetOptException e)
{
writeln(e.msg);
exit(1);
}
```


D style would be to use sth. like this (instead of try/catch):

```
scope(failure) {
  e.msg.writeln;
  1.exit;
}
```


Re: Why is there no std.stream anymore?

2017-12-11 Thread Seb via Digitalmars-d-learn
On Monday, 11 December 2017 at 22:58:53 UTC, Jordi Gutiérrez 
Hermoso wrote:
On Monday, 11 December 2017 at 21:21:51 UTC, Steven 
Schveighoffer wrote:

Use the undead repository:


Wow, really? Is the removal of stream from D some kind of error 
that hasn't been corrected yet?


Well of course you can use ranges for it, see e.g. this simple 
example:


---
void main(string[] args)
{
import std.conv, std.range, std.stdio;
foreach (d; 
File(__FILE_FULL_PATH__).byChunk(4096).join.take(5)) {

writefln("%s", d.to!char);
}
}
---

Run here: https://run.dlang.io/is/Ann9e9

Though if you need superb performance, iopipe or similar will be 
faster.


Re: Why is there no std.stream anymore?

2017-12-11 Thread flamencofantasy via Digitalmars-d-learn
On Monday, 11 December 2017 at 20:51:41 UTC, Jordi Gutiérrez 
Hermoso wrote:
I'd like to read from a file, one byte at a time, without 
loading the whole file in memory.


I was hoping I could do something like

   auto f = File("somefile");
   foreach(c; f.byChar) {
   process(c);
   }

but there appears to be no such way to do it anymore. Instead, 
the stdlib seems to provide several functions to do chunked 
reads from the file where I have to manually manage the buffer. 
I see that D1 had a stream, but it's no longer here and I 
understand ranges are supposed to be used instead.


What's the explanation here? Why is there no more stream and 
what am I supposed to use instead? Do I really need to be 
manually managing the read buffer myself?


This should work;

 scope f = new MmFile("somefile");
   foreach(c; cast(string)f[]) {
   process(c);
   }


Re: Why is there no std.stream anymore?

2017-12-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, December 11, 2017 22:58:53 Jordi Gutiérrez Hermoso via 
Digitalmars-d-learn wrote:
> On Monday, 11 December 2017 at 21:21:51 UTC, Steven Schveighoffer
>
> wrote:
> > Use the undead repository:
> Wow, really? Is the removal of stream from D some kind of error
> that hasn't been corrected yet?

std.stream was deemed to not be up to Phobos' current standards, and it's
not in line with Phobos' current design and implementation (most notably, it
doesn't support ranges at all). No one has cared enough to come up with an
alternative implementation and propose it for inclusion in Phobos. However,
for most needs, ranges do what you might do with a stream solution, and
std.bitmanip provides useful functions for byte-level manipulation (e.g.
taking the first elements from a range of ubytes and converting them to
int). Depending on what you're looking for,
http://code.dlang.org/packages/iopipe could also fit in quite well, though
it's very much a work in progress, and there are several serialization
libraries on code.dlang.org if that's more what you're looking for.

- Jonathan M Davis




Re: Why is there no std.stream anymore?

2017-12-11 Thread Steven Schveighoffer via Digitalmars-d-learn

On 12/11/17 5:58 PM, Jordi Gutiérrez Hermoso wrote:

On Monday, 11 December 2017 at 21:21:51 UTC, Steven Schveighoffer wrote:

Use the undead repository:


Wow, really? Is the removal of stream from D some kind of error that 
hasn't been corrected yet?


No, it was removed because it was considered subpar/obsolete. It doesn't 
jive with the rest of Phobos.


But modules that are removed are put into the undead repository for 
those who wish to continue using it.


-Steve


Re: File.byLine for either Windows / Unix newlines

2017-12-11 Thread Dennis via Digitalmars-d-learn

Thanks for your reply, that clears it up.

On Monday, 11 December 2017 at 21:13:11 UTC, Steven Schveighoffer 
wrote:

3. Stop using Windows ;)


Haha, if only the rest of the userbase would follow.


Re: Overloading float operators

2017-12-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, December 11, 2017 19:28:47 rumbu via Digitalmars-d-learn wrote:
> Is there any way to overload specific floating point operators?
> https://dlang.org/spec/expression.html#floating-point-comparisons

If those haven't been deprecated yet, they almost certainly will be. It was
decided that they were a mistake, and AFAIK, pretty much no one uses them.
opEquals and opCmp are all that there is for overloading comparison
operators.

> I'm using a decimal data type (a struct) and one of the possible
> values is NaN, that's why I need these operators.
>
> I know also that this also was discussed, but is there any way to
> separately implement == and !=, so both return true or false in
> the same time?
>
> The reason is the same: NaN == NaN = false and NaN != NaN = false
> in the same time.

You cannot overload == and != separately, but why would you need to? There's
no reason for a != b to not be the same as !(a == b) even with floating 
point
comparisons. e.g.

import std.stdio;

void main()
{
float f;
writeln(f == f);
writeln(f != f);
}

prints

false
true

- Jonathan M Davis



Re: Why is there no std.stream anymore?

2017-12-11 Thread Jordi Gutiérrez Hermoso via Digitalmars-d-learn
On Monday, 11 December 2017 at 21:21:51 UTC, Steven Schveighoffer 
wrote:

Use the undead repository:


Wow, really? Is the removal of stream from D some kind of error 
that hasn't been corrected yet?


Re: What's the proper way to use std.getopt?

2017-12-11 Thread Mike Wey via Digitalmars-d-learn

On 11-12-17 21:58, Jordi Gutiérrez Hermoso wrote:
but instead, the docstring from getopt is only generated if all 
arguments are valid, i.e. when it's the least needed because the user 
already knew what to input.


What's the proper style, then? Can someone show me a good example of how 
to use getopt and the docstring it automatically generates?



I would use something like this, print the help information for --help, 
print an error for invalid arguments:



```
try
{
auto helpInformation = getopt(
args,
"input|i", "The input", ,
"output|o", "The output", 
);

if (helpInformation.helpWanted)
{
defaultGetoptPrinter("Description", helpInformation.options);
exit(0);
}
}
catch (GetOptException e)
{
writeln(e.msg);
exit(1);
}
```

--
Mike Wey


Re: Why is there no std.stream anymore?

2017-12-11 Thread Steven Schveighoffer via Digitalmars-d-learn

On 12/11/17 3:51 PM, Jordi Gutiérrez Hermoso wrote:
I'd like to read from a file, one byte at a time, without loading the 
whole file in memory.


I was hoping I could do something like

    auto f = File("somefile");
    foreach(c; f.byChar) {
    process(c);
    }

but there appears to be no such way to do it anymore. Instead, the 
stdlib seems to provide several functions to do chunked reads from the 
file where I have to manually manage the buffer. I see that D1 had a 
stream, but it's no longer here and I understand ranges are supposed to 
be used instead.


What's the explanation here? Why is there no more stream and what am I 
supposed to use instead? Do I really need to be manually managing the 
read buffer myself?


Use the undead repository:

http://code.dlang.org/packages/undead

https://github.com/dlang/undeaD

https://github.com/dlang/undeaD/blob/master/src/undead/stream.d

-Steve


Re: File.byLine for either Windows / Unix newlines

2017-12-11 Thread Steven Schveighoffer via Digitalmars-d-learn

On 12/11/17 10:40 AM, Dennis wrote:
I'm on Windows and I recently got confused by how Phobos functions 
handle newlines.


```
void main() {
     import std.stdio;
     import std.path : buildPath, tempDir;

     auto path = buildPath(tempDir(), "test.txt");
     auto file = new File(path, "w");

     file.write("hello there!\n");   //actually writes hello there!\r\n
     file.write('\n');   //actually writes \r\n
     file.rawWrite("\n");    //actually writes \n
     //file.rawWrite('\n');  //doesn't compile
     file.close();

     //byLine uses \n as default terminator, so a trailing \r is kept
     writeln(File(path).byLine.front~"huh?");   //prints "huh?o there!"
}
```

- Why do these functions behave like that?
- What is the easiest way to iterate over a file by line that works with 
both \r\n and \n line endings? I prefer not to write a new method for this.


Please note that D uses FILE * as its underlying implementation. This 
means that whatever the C library does, D's library does.


In the case of Windows, there is this lovely concept that line endings 
should be \r\n, not just \n. So the C library helpfully inserts \r 
whenever it sees a \n. This is known as "text mode" as opposed to 
"binary mode".


rawWrite temporarily sets the mode to binary mode, then restores the 
original mode. This is why the \n is not translated there.


Here's the fun part: the default open mode is "rb". See the docs here: 
https://dlang.org/phobos/std_stdio.html#.File.this


So you are actually opening the file in binary mode, whereas you were 
writing it in text mode.


You can fix this in one of 3 ways:
1. Open your file for writing with "wb". This will not store the \r by 
default.
2. Open your file for reading with "r" (e.g. File(path, "r")). This will 
replace the \r\n with just \n in the underlying C library.

3. Stop using Windows ;)

-Steve


Re: Tuple Array Sorting

2017-12-11 Thread Biotronic via Digitalmars-d-learn

On Monday, 11 December 2017 at 19:46:04 UTC, Vino wrote:


import std.algorithm;
import std.container.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.stdio: writefln, writeln;
import std.typecons: Tuple, tuple;
import std.range: chain;

void main () {
auto FFs =  ["C:\\Temp\\BACKUP", "C:\\Temp\\EXPORT", 
"C:\\Temp\\PROD_TEAM"];

foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name, 
a.timeCreated)));
writefln("%(%-(%-63s %s %)\n%)", chain(dFiles[]).sort!((a, b) 
=> a[1] < b[1]));

}
}


So let's go through this code then, shall we?

Edited a bit for clarity:

// For each directory (*one at a time*),
foreach(d; FFs[]) {
// List all the folders
auto dFiles = Array!(Tuple!(string, SysTime))(
dirEntries(d, SpanMode.shallow)
// Not the files,
.filter!(a => a.isDir)
// Grab only the information we want,
.map!(a => tuple(a.name, a.timeCreated)));
// And print a sorted list of the subfolders of the 
current folder.
writefln("%(%-(%-63s %s %)\n%)", 
chain(dFiles[]).sort!((a, b) => a[1] < b[1]));

}

This will go through C:\Temp\BACKUP, and display a sorted list of 
all the subfolders in that folder. Then it will do the same for 
C:\Temp\EXPORT, and then for C:\Temp\PROD_TEAM.


No subfolder of C:\Temp\PROD_TEAM will be displayed before 
anything in C:\Temp\BACKUP, because you're sorting only one set 
of subfolders at a time.


What you're essentially doing, is sorting [6,2,4] and [3,5,1] 
separately, and printing them separately, giving the illusion of 
having sorted them into the array [2,4,6,1,3,5]. As you correctly 
point out, this is not what you wanted. The code I presented 
avoids this by joining the lists for all the folders.


Your code could also be simplified a bit - there's no need for 
the call to chain, and calling dirEntries.filter.map.array is 
easier to read and write than having Array!(Tuple!(string, 
SysTime)) at the front.


In case my code from earlier was hard to understand, here's 
another version~, more closely modeled to your code:


import std.algorithm : map, filter, sort;
import std.array : array;
import std.file : SpanMode, dirEntries, isDir;
import std.stdio : writefln;
import std.typecons : Tuple, tuple;
import std.datetime : SysTime;

void main() {
// The folders we want to look in.
auto folders = [`C:\Windows`, `C:\Program Files`, `C:\Users`];

// We'll put all the subfolders we find here, so we can sort 
them in the end.

Tuple!(string, SysTime)[] subFolders;

// Look through each folder in turn.
foreach (folder; folders) {
// Get all entries in the folder,
auto entries = dirEntries(folder, SpanMode.shallow);
// Get rid of files,
auto folderEntries = entries.filter!(a => a.isDir);
// Grab the interesting parts,
auto interestingParts = folderEntries.map!(a => 
tuple(a.name, a.timeCreated));

// And add it to the array.
subFolders ~= interestingParts.array;
}
// Sort the entire array.
auto sorted = subFolders.sort!((a, b) => a[1] < b[1]);
// And print it!
writefln("%(%-(%-63s %s %)\n%)", sorted);
}


What's the proper way to use std.getopt?

2017-12-11 Thread Jordi Gutiérrez Hermoso via Digitalmars-d-learn
I don't quite understand what to do if getopt throws. I would 
have hoped for something like


   int arg1;
   string arg2;
   auto parser = getopt("opt1", "docstring 1", , "opt2", 
"docstring 2", );

   try {
 auto opts = parser.parse(args)
   }
   except(BadArguments) {
 parser.showHelpString();
   }

but instead, the docstring from getopt is only generated if all 
arguments are valid, i.e. when it's the least needed because the 
user already knew what to input.


What's the proper style, then? Can someone show me a good example 
of how to use getopt and the docstring it automatically generates?


Re: return ref this -dip1000

2017-12-11 Thread vit via Digitalmars-d-learn

On Monday, 11 December 2017 at 20:44:06 UTC, Eugene Wissner wrote:

On Monday, 11 December 2017 at 20:40:09 UTC, vit wrote:

This code doesn't compile with -dip1000:

struct Foo{
int foo;


ref int bar(){

return foo;
}
}

Error: returning `this.foo` escapes a reference to parameter 
`this`, perhaps annotate with `return`



How can be annotated this parameter with 'return ref' ?


struct Foo{
int foo;


ref int bar() return {

return foo;
}
}


thank you.


Why is there no std.stream anymore?

2017-12-11 Thread Jordi Gutiérrez Hermoso via Digitalmars-d-learn
I'd like to read from a file, one byte at a time, without loading 
the whole file in memory.


I was hoping I could do something like

   auto f = File("somefile");
   foreach(c; f.byChar) {
   process(c);
   }

but there appears to be no such way to do it anymore. Instead, 
the stdlib seems to provide several functions to do chunked reads 
from the file where I have to manually manage the buffer. I see 
that D1 had a stream, but it's no longer here and I understand 
ranges are supposed to be used instead.


What's the explanation here? Why is there no more stream and what 
am I supposed to use instead? Do I really need to be manually 
managing the read buffer myself?


Re: return ref this -dip1000

2017-12-11 Thread Eugene Wissner via Digitalmars-d-learn

On Monday, 11 December 2017 at 20:40:09 UTC, vit wrote:

This code doesn't compile with -dip1000:

struct Foo{
int foo;


ref int bar(){

return foo;
}
}

Error: returning `this.foo` escapes a reference to parameter 
`this`, perhaps annotate with `return`



How can be annotated this parameter with 'return ref' ?


struct Foo{
int foo;


ref int bar() return {

return foo;
}
}



return ref this -dip1000

2017-12-11 Thread vit via Digitalmars-d-learn

This code doesn't compile with -dip1000:

struct Foo{
int foo;


ref int bar(){

return foo;
}
}

Error: returning `this.foo` escapes a reference to parameter 
`this`, perhaps annotate with `return`



How can be annotated this parameter with 'return ref' ?


Re: Overloading float operators

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

On 12/11/2017 08:28 PM, rumbu wrote:

Is there any way to overload specific floating point operators?
https://dlang.org/spec/expression.html#floating-point-comparisons


Those don't seem to work anymore. At least since 2.073, dmd rejects them 
and says to use std.math.isNaN instead. Looks like someone forgot to 
upate the spec. I couldn't find anything in the changelog either.


I'm using a decimal data type (a struct) and one of the possible values 
is NaN, that's why I need these operators.


You can return float.nan from opCmp to mean "unordered":


struct S
{
bool isNaN = true;
int value;

this(int value) { this.isNaN = false; this.value = value; }

bool opEquals(const S other) const pure nothrow @safe @nogc
{
return !this.isNaN && !other.isNaN && this.value == other.value;
}

float opCmp(const S other) const pure nothrow @safe @nogc
{
if (this.isNaN || other.isNaN) return float.nan;
if (this.value < other.value) return -1;
if (this.value > other.value) return 1;
return 0;
}
}

void main()
{
S s1; // NaN
S s2; // NaN

assert(s1 != s2); // neither equal ...
assert(!(s1 < s2)); // nor less than ...
assert(!(s1 > s2)); // nor greater
}


I know also that this also was discussed, but is there any way to 
separately implement == and !=, so both return true or false in the same 
time?


I don't think so.

The reason is the same: NaN == NaN = false and NaN != NaN = false in the 
same time.


But NaN != NaN is true.


Re: Tuple Array Sorting

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

On Monday, 11 December 2017 at 19:23:40 UTC, Seb wrote:

On Monday, 11 December 2017 at 16:15:14 UTC, Vino wrote:

On Monday, 11 December 2017 at 15:54:11 UTC, Biotronic wrote:

  [...]


Hi Biotronic,

 I tried your code with multiple folder's , but no luck the 
output is not sorted.


Program:
import std.algorithm: filter, map, sort;
import std.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.stdio: writefln, writeln;
import std.typecons: Tuple, tuple;

void main () {
auto FFs =  ["C:\\Temp\\sapnas2\\BACKUP", 
"C:\\Temp\\sapnas2\\EXPORT", "C:\\Temp\\sapnas2\\PROD_TEAM"];

auto sorted = FFs
.map!(a => dirEntries(a, SpanMode.shallow))
.join
.filter!(a => a.isDir)
.map!(a => tuple(a.name, a.timeCreated.toSimpleString[0 .. 
20]))

.array
.sort!((a,b) => a[1] > b[1]);
writefln("%( %( %-63s %s %) \n%)", sorted);
}

From,
Vino.B


Your program still contains toSimpleString in the sort lambda. 
Have you, as suggested, removed it?
As Biotronic explained, sorting on the string representation of 
dates can't work.


Hi,

 Yes, I have changed the code as below, and removed the 
toSimpleString, even then no luck.


Code:
import std.algorithm;
import std.container.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.stdio: writefln, writeln;
import std.typecons: Tuple, tuple;
import std.range: chain;

void main () {
auto FFs =  ["C:\\Temp\\BACKUP", "C:\\Temp\\EXPORT", 
"C:\\Temp\\PROD_TEAM"];

foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name, 
a.timeCreated)));
writefln("%(%-(%-63s %s %)\n%)", chain(dFiles[]).sort!((a, b) => 
a[1] < b[1]));

}
}

Output
C:\Temp\BACKUP\DND3 
2017-Sep-05 14:31:00.7037169
C:\Temp\BACKUP\dir1 
2017-Sep-06 16:06:42.7223837
C:\Temp\BACKUP\dir2 
2017-Sep-09 22:44:11.7604069
C:\Temp\BACKUP\dir3 
2017-Dec-10 06:56:07.5122231
C:\Temp\BACKUP\t1   
2017-Dec-11 04:10:02.6413853


C:\Temp\EXPORT\DND6 
2017-Sep-05 14:31:00.8909172
C:\Temp\PROD_TEAM\DND1  
2017-Sep-05 14:31:01.8269189


Required Output:
C:\Temp\BACKUP\DND3 
2017-Sep-05 14:31:00.7037169
C:\Temp\EXPORT\DND6 
2017-Sep-05 14:31:00.8909172
C:\Temp\PROD_TEAM\DND1  
2017-Sep-05 14:31:01.8269189
C:\Temp\BACKUP\dir1 
2017-Sep-06 16:06:42.7223837
C:\Temp\BACKUP\dir2 
2017-Sep-09 22:44:11.7604069
C:\Temp\BACKUP\dir3 
2017-Dec-10 06:56:07.5122231
C:\Temp\BACKUP\t1   
2017-Dec-11 04:10:02.6413853


From,
Vino.B



Overloading float operators

2017-12-11 Thread rumbu via Digitalmars-d-learn

Is there any way to overload specific floating point operators?
https://dlang.org/spec/expression.html#floating-point-comparisons

I'm using a decimal data type (a struct) and one of the possible 
values is NaN, that's why I need these operators.


I know also that this also was discussed, but is there any way to 
separately implement == and !=, so both return true or false in 
the same time?


The reason is the same: NaN == NaN = false and NaN != NaN = false 
in the same time.




Re: Tuple Array Sorting

2017-12-11 Thread Seb via Digitalmars-d-learn

On Monday, 11 December 2017 at 16:15:14 UTC, Vino wrote:

On Monday, 11 December 2017 at 15:54:11 UTC, Biotronic wrote:

  [...]


Hi Biotronic,

 I tried your code with multiple folder's , but no luck the 
output is not sorted.


Program:
import std.algorithm: filter, map, sort;
import std.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.stdio: writefln, writeln;
import std.typecons: Tuple, tuple;

void main () {
auto FFs =  ["C:\\Temp\\sapnas2\\BACKUP", 
"C:\\Temp\\sapnas2\\EXPORT", "C:\\Temp\\sapnas2\\PROD_TEAM"];

auto sorted = FFs
.map!(a => dirEntries(a, SpanMode.shallow))
.join
.filter!(a => a.isDir)
.map!(a => tuple(a.name, a.timeCreated.toSimpleString[0 .. 20]))
.array
.sort!((a,b) => a[1] > b[1]);
writefln("%( %( %-63s %s %) \n%)", sorted);
}

From,
Vino.B


Your program still contains toSimpleString in the sort lambda. 
Have you, as suggested, removed it?
As Biotronic explained, sorting on the string representation of 
dates can't work.


Re: Tuple Array Sorting

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

On Monday, 11 December 2017 at 15:54:11 UTC, Biotronic wrote:

On Monday, 11 December 2017 at 15:33:08 UTC, Vino wrote:

On Monday, 11 December 2017 at 15:15:47 UTC, Biotronic wrote:

  [...]


Hi,

 I tired that but no luck, below is the output, in your code 
you have one folder "auto folders =  ["D:\\Dev"];" if you have 
multiple folder then output is not sorted.


C:\Temp\BACKUP\dir2 
2017-Sep-09 22:44:11
C:\Temp\BACKUP\dir1 
2017-Sep-06 16:06:42
C:\Temp\BACKUP\DND3 
2017-Sep-05 14:31:00
C:\Temp\BACKUP\t1   
2017-Dec-11 04:10:02
C:\Temp\BACKUP\dir3 
2017-Dec-10 06:56:07
C:\Temp\EXPORT\DND6 
2017-Sep-05 14:31:00
C:\Temp\PROD_TEAM\DND1  
2017-Sep-05 14:31:01


Are you sure that's the output from my code? Let's step through 
the code:


// Iterating over folders:
folders
// Create a range where each element is a range of DirEntry
// in the given folder.
.map!(a => dirEntries(a, SpanMode.shallow))
// Join these together to a single range of DirEntry 
instead of

// a range-of-ranges-of-DirEntry.
.join
// Remove anything that's not a folder.
.filter!(a => a.isDir)
// Grab the information we actually care about.
.map!(a => tuple(a.name, a.timeCreated))
// Enumerate to an array, so we can sort it.
.array
// Sort this array by the second tuple element 
(timeCreated).

.sort!((a,b) => a[1] > b[1]);

If this code does not do what you're asking, there's a bug 
outside of the code, probably in the standard library.


If instead you are invoking the program multiple times with a 
single folder each time, the output you describe is to be 
expected.


Apart from that, I'm not sure what could be wrong.

--
  Biotronic


Hi Biotronic,

 I tried your code with multiple folder's , but no luck the 
output is not sorted.


Program:
import std.algorithm: filter, map, sort;
import std.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.stdio: writefln, writeln;
import std.typecons: Tuple, tuple;

void main () {
auto FFs =  ["C:\\Temp\\sapnas2\\BACKUP", 
"C:\\Temp\\sapnas2\\EXPORT", "C:\\Temp\\sapnas2\\PROD_TEAM"];

auto sorted = FFs
.map!(a => dirEntries(a, SpanMode.shallow))
.join
.filter!(a => a.isDir)
.map!(a => tuple(a.name, a.timeCreated.toSimpleString[0 .. 20]))
.array
.sort!((a,b) => a[1] > b[1]);
writefln("%( %( %-63s %s %) \n%)", sorted);
}

From,
Vino.B



Re: Tuple Array Sorting

2017-12-11 Thread Biotronic via Digitalmars-d-learn

On Monday, 11 December 2017 at 15:33:08 UTC, Vino wrote:

On Monday, 11 December 2017 at 15:15:47 UTC, Biotronic wrote:

On Monday, 11 December 2017 at 14:52:35 UTC, Vino wrote:

Example Program and Output

import std.algorithm: filter, map, sort;
import std.container.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.range: chain;
import std.stdio: writefln;
import std.typecons: Tuple, tuple;

void main () {
auto FFs =  Array!(string)("C:\\Temp\\BACKUP", 
"C:\\Temp\\EXPORT", "C:\\Temp\\PROD_TEAM");

int AgeSize = 2;
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, string))(dirEntries(d, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => 
tuple(a.name, a.timeCreated.toSimpleString[0 .. 20])));
writefln("%(%-(%-63s %s %)\n%)", chain(dFiles[]).sort!((a,b) 
=> a[0] > b[0]));

}
}


You're somewhat close. You're sorting based on the 0th element 
of your tuples, while you should sort on the 1st. Something 
like this:


import std.algorithm: filter, map, sort;
import std.array : array;
import std.file: SpanMode, dirEntries, isDir ;
import std.range: join;
import std.stdio: writefln;
import std.typecons: tuple;

void main () {
auto folders =  ["D:\\Dev"];

auto sorted = folders
.map!(a => dirEntries(a, SpanMode.shallow))
.join
.filter!(a => a.isDir)
.map!(a => tuple(a.name, 
a.timeCreated.toSimpleString[0 .. 20]))

.array
.sort!((a,b) => a[1] > b[1]);

writefln("%( %( %-63s %s %) \n%)", sorted);
}

--
  Biotronic


Hi,

 I tired that but no luck, below is the output, in your code 
you have one folder "auto folders =  ["D:\\Dev"];" if you have 
multiple folder then output is not sorted.


C:\Temp\BACKUP\dir2 
2017-Sep-09 22:44:11
C:\Temp\BACKUP\dir1 
2017-Sep-06 16:06:42
C:\Temp\BACKUP\DND3 
2017-Sep-05 14:31:00
C:\Temp\BACKUP\t1   
2017-Dec-11 04:10:02
C:\Temp\BACKUP\dir3 
2017-Dec-10 06:56:07
C:\Temp\EXPORT\DND6 
2017-Sep-05 14:31:00
C:\Temp\PROD_TEAM\DND1  
2017-Sep-05 14:31:01


Are you sure that's the output from my code? Let's step through 
the code:


// Iterating over folders:
folders
// Create a range where each element is a range of DirEntry
// in the given folder.
.map!(a => dirEntries(a, SpanMode.shallow))
// Join these together to a single range of DirEntry instead 
of

// a range-of-ranges-of-DirEntry.
.join
// Remove anything that's not a folder.
.filter!(a => a.isDir)
// Grab the information we actually care about.
.map!(a => tuple(a.name, a.timeCreated))
// Enumerate to an array, so we can sort it.
.array
// Sort this array by the second tuple element (timeCreated).
.sort!((a,b) => a[1] > b[1]);

If this code does not do what you're asking, there's a bug 
outside of the code, probably in the standard library.


If instead you are invoking the program multiple times with a 
single folder each time, the output you describe is to be 
expected.


Apart from that, I'm not sure what could be wrong.

--
  Biotronic


Re: Tuple Array Sorting

2017-12-11 Thread Biotronic via Digitalmars-d-learn

On Monday, 11 December 2017 at 15:33:08 UTC, Vino wrote:
 I tired that but no luck, below is the output, in your code 
you have one folder "auto folders =  ["D:\\Dev"];" if you have 
multiple folder then output is not sorted.


Works on my machine. Of course, since time toSimpleString returns 
non-ISO8601, the sorting might not make perfect sense 
("2017-Dec-12" < "2017-Jan-01"). Testing with multiple folders 
gives perfectly sorted output. If you want it sorted by date 
instead of by string representation of date, feel free to remove 
.toSimpleString[0 .. 20].


--
  Biotronic


File.byLine for either Windows / Unix newlines

2017-12-11 Thread Dennis via Digitalmars-d-learn
I'm on Windows and I recently got confused by how Phobos 
functions handle newlines.


```
void main() {
import std.stdio;
import std.path : buildPath, tempDir;

auto path = buildPath(tempDir(), "test.txt");
auto file = new File(path, "w");

file.write("hello there!\n");   //actually writes hello 
there!\r\n

file.write('\n');   //actually writes \r\n
file.rawWrite("\n");//actually writes \n
//file.rawWrite('\n');  //doesn't compile
file.close();

//byLine uses \n as default terminator, so a trailing \r is 
kept
writeln(File(path).byLine.front~"huh?");   //prints "huh?o 
there!"

}
```

- Why do these functions behave like that?
- What is the easiest way to iterate over a file by line that 
works with both \r\n and \n line endings? I prefer not to write a 
new method for this.






Re: Tuple Array Sorting

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

On Monday, 11 December 2017 at 15:15:47 UTC, Biotronic wrote:

On Monday, 11 December 2017 at 14:52:35 UTC, Vino wrote:

Example Program and Output

import std.algorithm: filter, map, sort;
import std.container.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.range: chain;
import std.stdio: writefln;
import std.typecons: Tuple, tuple;

void main () {
auto FFs =  Array!(string)("C:\\Temp\\BACKUP", 
"C:\\Temp\\EXPORT", "C:\\Temp\\PROD_TEAM");

int AgeSize = 2;
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, string))(dirEntries(d, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => 
tuple(a.name, a.timeCreated.toSimpleString[0 .. 20])));
writefln("%(%-(%-63s %s %)\n%)", chain(dFiles[]).sort!((a,b) 
=> a[0] > b[0]));

}
}


You're somewhat close. You're sorting based on the 0th element 
of your tuples, while you should sort on the 1st. Something 
like this:


import std.algorithm: filter, map, sort;
import std.array : array;
import std.file: SpanMode, dirEntries, isDir ;
import std.range: join;
import std.stdio: writefln;
import std.typecons: tuple;

void main () {
auto folders =  ["D:\\Dev"];

auto sorted = folders
.map!(a => dirEntries(a, SpanMode.shallow))
.join
.filter!(a => a.isDir)
.map!(a => tuple(a.name, a.timeCreated.toSimpleString[0 
.. 20]))

.array
.sort!((a,b) => a[1] > b[1]);

writefln("%( %( %-63s %s %) \n%)", sorted);
}

--
  Biotronic


Hi,

 I tired that but no luck, below is the output, in your code you 
have one folder "auto folders =  ["D:\\Dev"];" if you have 
multiple folder then output is not sorted.


C:\Temp\BACKUP\dir2 
2017-Sep-09 22:44:11
C:\Temp\BACKUP\dir1 
2017-Sep-06 16:06:42
C:\Temp\BACKUP\DND3 
2017-Sep-05 14:31:00
C:\Temp\BACKUP\t1   
2017-Dec-11 04:10:02
C:\Temp\BACKUP\dir3 
2017-Dec-10 06:56:07
C:\Temp\EXPORT\DND6 
2017-Sep-05 14:31:00
C:\Temp\PROD_TEAM\DND1  
2017-Sep-05 14:31:01


From,
Vino.B



Re: Tuple Array Sorting

2017-12-11 Thread Biotronic via Digitalmars-d-learn

On Monday, 11 December 2017 at 14:52:35 UTC, Vino wrote:

Example Program and Output

import std.algorithm: filter, map, sort;
import std.container.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.range: chain;
import std.stdio: writefln;
import std.typecons: Tuple, tuple;

void main () {
auto FFs =  Array!(string)("C:\\Temp\\BACKUP", 
"C:\\Temp\\EXPORT", "C:\\Temp\\PROD_TEAM");

int AgeSize = 2;
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, string))(dirEntries(d, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name, 
a.timeCreated.toSimpleString[0 .. 20])));
writefln("%(%-(%-63s %s %)\n%)", chain(dFiles[]).sort!((a,b) => 
a[0] > b[0]));

}
}


You're somewhat close. You're sorting based on the 0th element of 
your tuples, while you should sort on the 1st. Something like 
this:


import std.algorithm: filter, map, sort;
import std.array : array;
import std.file: SpanMode, dirEntries, isDir ;
import std.range: join;
import std.stdio: writefln;
import std.typecons: tuple;

void main () {
auto folders =  ["D:\\Dev"];

auto sorted = folders
.map!(a => dirEntries(a, SpanMode.shallow))
.join
.filter!(a => a.isDir)
.map!(a => tuple(a.name, a.timeCreated.toSimpleString[0 
.. 20]))

.array
.sort!((a,b) => a[1] > b[1]);

writefln("%( %( %-63s %s %) \n%)", sorted);
}

--
  Biotronic


Re: Tuple Array Sorting

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

On Monday, 11 December 2017 at 14:25:16 UTC, Vino wrote:

On Monday, 11 December 2017 at 13:58:49 UTC, Vino wrote:

Hi All,

  Request your help in tuple array sorting, I have a function 
which returns tuple values as below so how do i sort this type 
of array based on the time stamp(Acceding order) .


Eg:
C:\Temp\EXPORT\dir2   2017-Sep-06 16:06:58
C:\Temp\BACKUP\dir2   2017-Sep-09 22:44:11
C:\Temp\TEAM\dir1 2017-Sep-10 16:06:42
C:\Temp\USER\dir3 2017-Sep-05 16:06:57

Required Output:
C:\Temp\USER\dir3 2017-Sep-05 16:06:57
C:\Temp\EXPORT\dir2   2017-Sep-06 16:06:58
C:\Temp\BACKUP\dir2   2017-Sep-09 22:44:11
C:\Temp\TEAM\dir1 2017-Sep-10 16:06:42

From,
Vino.B


A small additional Information

C:\Temp\EXPORT\dir2   2017-Sep-06 16:06:58 - 
Array!(Tuple!(string, string)) (Array 1)
C:\Temp\BACKUP\dir2   2017-Sep-09 22:44:11 - 
Array!(Tuple!(string, string)) (Array 2)
C:\Temp\TEAM\dir1 2017-Sep-10 16:06:42 - 
Array!(Tuple!(string, string)) (Array 3)
C:\Temp\USER\dir3 2017-Sep-05 16:06:57 - 
Array!(Tuple!(string, string)) (Array 4)


 Required Output:
C:\Temp\USER\dir3 2017-Sep-05 16:06:57 - 
Array!(Tuple!(string, string)) (Array 4)
C:\Temp\EXPORT\dir2   2017-Sep-06 16:06:58 - 
Array!(Tuple!(string, string)) (Array 1)
C:\Temp\BACKUP\dir2   2017-Sep-09 22:44:11 - 
Array!(Tuple!(string, string)) (Array 2)
C:\Temp\TEAM\dir1 2017-Sep-10 16:06:42 - 
Array!(Tuple!(string, string)) (Array 3)


From,
Vino.B


Example Program and Output

import std.algorithm: filter, map, sort;
import std.container.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.range: chain;
import std.stdio: writefln;
import std.typecons: Tuple, tuple;

void main () {
auto FFs =  Array!(string)("C:\\Temp\\BACKUP", 
"C:\\Temp\\EXPORT", "C:\\Temp\\PROD_TEAM");

int AgeSize = 2;
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, string))(dirEntries(d, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name, 
a.timeCreated.toSimpleString[0 .. 20])));
writefln("%(%-(%-63s %s %)\n%)", chain(dFiles[]).sort!((a,b) => 
a[0] > b[0]));

}
}

Output

C:\Temp\BACKUP\DND3 
2017-Sep-05 14:31:00
C:\Temp\BACKUP\dir1 
2017-Sep-06 16:06:42
C:\Temp\BACKUP\dir2 
2017-Sep-09 22:44:11
C:\Temp\BACKUP\dir3 
2017-Dec-10 06:56:07
C:\Temp\BACKUP\t1   
2017-Dec-11 04:10:02
C:\Temp\EXPORT\DND6 
2017-Sep-05 14:31:00
C:\Temp\PROD_TEAM\DND1  
2017-Sep-05 14:31:01


Output Required
C:\Temp\BACKUP\DND3 
2017-Sep-05 14:31:00
C:\Temp\EXPORT\DND6 
2017-Sep-05 14:31:00
C:\Temp\PROD_TEAM\DND1  
2017-Sep-05 14:31:01
C:\Temp\BACKUP\dir1 
2017-Sep-06 16:06:42
C:\Temp\BACKUP\dir2 
2017-Sep-09 22:44:11
C:\Temp\BACKUP\dir3 
2017-Dec-10 06:56:07
C:\Temp\BACKUP\t1   
2017-Dec-11 04:10:02



From,
Vino.B


Re: Tuple Array Sorting

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

On Monday, 11 December 2017 at 13:58:49 UTC, Vino wrote:

Hi All,

  Request your help in tuple array sorting, I have a function 
which returns tuple values as below so how do i sort this type 
of array based on the time stamp(Acceding order) .


Eg:
C:\Temp\EXPORT\dir2   2017-Sep-06 16:06:58
C:\Temp\BACKUP\dir2   2017-Sep-09 22:44:11
C:\Temp\TEAM\dir1 2017-Sep-10 16:06:42
C:\Temp\USER\dir3 2017-Sep-05 16:06:57

Required Output:
C:\Temp\USER\dir3 2017-Sep-05 16:06:57
C:\Temp\EXPORT\dir2   2017-Sep-06 16:06:58
C:\Temp\BACKUP\dir2   2017-Sep-09 22:44:11
C:\Temp\TEAM\dir1 2017-Sep-10 16:06:42

From,
Vino.B


A small additional Information

C:\Temp\EXPORT\dir2   2017-Sep-06 16:06:58 - 
Array!(Tuple!(string, string)) (Array 1)
C:\Temp\BACKUP\dir2   2017-Sep-09 22:44:11 - 
Array!(Tuple!(string, string)) (Array 2)
C:\Temp\TEAM\dir1 2017-Sep-10 16:06:42 - 
Array!(Tuple!(string, string)) (Array 3)
C:\Temp\USER\dir3 2017-Sep-05 16:06:57 - 
Array!(Tuple!(string, string)) (Array 4)


 Required Output:
C:\Temp\USER\dir3 2017-Sep-05 16:06:57 - 
Array!(Tuple!(string, string)) (Array 4)
C:\Temp\EXPORT\dir2   2017-Sep-06 16:06:58 - 
Array!(Tuple!(string, string)) (Array 1)
C:\Temp\BACKUP\dir2   2017-Sep-09 22:44:11 - 
Array!(Tuple!(string, string)) (Array 2)
C:\Temp\TEAM\dir1 2017-Sep-10 16:06:42 - 
Array!(Tuple!(string, string)) (Array 3)


From,
Vino.B



Re: Clarify "Starting as a Contributor" document

2017-12-11 Thread Dukc via Digitalmars-d-learn

On Sunday, 10 December 2017 at 08:18:17 UTC, Ali Çehreli wrote:

This page is very good:

  https://wiki.dlang.org/Starting_as_a_Contributor

I need clarifications


Another oddity: Someone has apparently made DRuntime build to use 
../dmd/generated/windows/32/dmd instead of the "system" dmd 
recently. Perhaps the idea here is that I do not have to go 
replacing my system dmd anymore.


But the problem is that when I build dmd, for some reason, the 
build file deletes that generated dmd at the end. Can be resolved 
by moving the dmd manually to that directory, but that is not 
explained at the web page. Should we tweak dmd to build into the 
generated directory instead of working directory, or tweak 
DRuntime to use ../dmd/src/dmd instead? Or am I missing something?





Tuple Array Sorting

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

Hi All,

  Request your help in tuple array sorting, I have a function 
which returns tuple values as below so how do i sort this type of 
array based on the time stamp(Acceding order) .


Eg:
C:\Temp\EXPORT\dir2   2017-Sep-06 16:06:58
C:\Temp\BACKUP\dir2   2017-Sep-09 22:44:11
C:\Temp\TEAM\dir1 2017-Sep-10 16:06:42
C:\Temp\USER\dir3 2017-Sep-05 16:06:57

Required Output:
C:\Temp\USER\dir3 2017-Sep-05 16:06:57
C:\Temp\EXPORT\dir2   2017-Sep-06 16:06:58
C:\Temp\BACKUP\dir2   2017-Sep-09 22:44:11
C:\Temp\TEAM\dir1 2017-Sep-10 16:06:42

From,
Vino.B


Re: libcurl acting differently to curl.exe

2017-12-11 Thread ikod via Digitalmars-d-learn

On Monday, 11 December 2017 at 03:53:25 UTC, Josh wrote:

The POST C code was:

/* Sample code generated by the curl command line tool 
**

 * All curl_easy_setopt() options are documented at:
 * https://curl.haxx.se/libcurl/c/curl_easy_setopt.html


Maybe off-topic but you can try 
http://code.dlang.org/packages/requests.


Re: check mountpoint status and send email on timeout/failure?

2017-12-11 Thread Nicholas Wilson via Digitalmars-d-learn

On Monday, 11 December 2017 at 10:50:17 UTC, biocyberman wrote:
For someone using NFS or some other remote filesystems, one may 
have experienced many times the nasty silent hang. For example, 
if I run `ls /mnt/remote/nfsmount`, and the remote NFS server 
is down while /mnt/remote/nfsmount was mounted, it will take 
very long time or forever for the `ls` command to return an 
error. Imagine if it were not `ls` but a data producing 
program, or user's home directly, it will be very inconvenient. 
Since I want to learn D, I want to write a program that does:
1. Check a path and to see it is a mount point. If it is not a 
mount point, try to mount it, and send an email. If it is a 
mount point, go to step 2.
2. If it is amount point, but fails to response after a certain 
time period (e.g 5 seconds), then send an email.


I know nothing about how to write it in D, or which library to 
use. So, some help please.


You will need to use the system APIs for that I assume, nothing 
special for that. Just search for how to do what you want, 
probably in C, and translate that to D.


As for the email, not so sure.


Re: Seed Value for reduce function

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

On Sunday, 10 December 2017 at 06:01:49 UTC, Ali Çehreli wrote:

On 12/09/2017 06:19 PM, Vino wrote:


[...]


When no seed value is specified, fold (and reduce) take the 
first element as the seed. When the range is empty, then there 
is a run-time failure:


object.Exception@/usr/include/dmd/phobos/std/algorithm/iteration.d(2794): 
Cannot reduce an empty input range w/o an explicit seed value.

The solution is to provide an explicit seed value:

import std.container;
import std.file;
import std.algorithm;

void main() {
const d = "/tmp/empty_folder";
const Size = 42;
auto SdFiles = Array!ulong(dirEntries(d, 
SpanMode.depth).map!(a => a.size).fold!((a,b) => a + 
b)(size_t(0)))[].filter!(a => a  > Size);

}

I chose size_t(0) but you can use a variable, size_t.init, etc.

Ali


Hi Ali,
 Thank you very much, was able to apply your logic which resolved 
the issue.


From,
Vino.B


check mountpoint status and send email on timeout/failure?

2017-12-11 Thread biocyberman via Digitalmars-d-learn
For someone using NFS or some other remote filesystems, one may 
have experienced many times the nasty silent hang. For example, 
if I run `ls /mnt/remote/nfsmount`, and the remote NFS server is 
down while /mnt/remote/nfsmount was mounted, it will take very 
long time or forever for the `ls` command to return an error. 
Imagine if it were not `ls` but a data producing program, or 
user's home directly, it will be very inconvenient. Since I want 
to learn D, I want to write a program that does:
1. Check a path and to see it is a mount point. If it is not a 
mount point, try to mount it, and send an email. If it is a mount 
point, go to step 2.
2. If it is amount point, but fails to response after a certain 
time period (e.g 5 seconds), then send an email.


I know nothing about how to write it in D, or which library to 
use. So, some help please.