Re: Python and D (PyD)

2017-11-28 Thread Fat_Umpalumpa via Digitalmars-d-learn
you need to tell the compiler where to look to find pyd (which 
it can't find in '/Library/D/dmd/src/phobos' or 
'/Library/D/dmd/src/druntime/import').
If you are invoking the compiler yourself use the `-I` switch 
(`-Ipath/to/pyd`).
Or if you are using dub (I recommend this) make sure that is is 
in your list of dependencies.


Ahhh thank you! I'm still new to the d language and dub worked 
fine.





Re: Storing Formatted Array Value

2017-11-28 Thread Petar via Digitalmars-d-learn

On Wednesday, 29 November 2017 at 07:08:12 UTC, Vino wrote:

Hi All,

Request your help, with the below code I am able to print the 
value of the array without brackects , but can some on help me 
on hot to store this output to a variable


Program:
import std.stdio;
import std.container;

void main()
{
   auto test = Array!string("Test1", "Test2");
   writefln("%(%s, %)",test[]); // output : "Test1", "Test2"

   // Similar like this
   auto res = `writefln("%(%s, %)",test[])`;
   writeln(res);
}

Output of res should look like : "Test1", "Test2" (Without [] 
brackets).



From,
Vino.B


https://dlang.org/phobos/std_format is your friend:

// https://run.dlang.io/is/sUkOX0

import std.container;
import std.format;
import std.stdio;

void main()
{
   auto test = Array!string("Test1", "Test2");
   writefln("%(%s, %)",test[]);

   // Similar like this
   auto res = "%(%s, %)".format(test[]);
   writeln(res);

   auto res2 = "%-(%s, %)".format(test[]);
   writeln(res2);
}


Re: Python and D (PyD)

2017-11-28 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 29 November 2017 at 06:34:53 UTC, Fat_Umpalumpa 
wrote:
Hello, I have searched these forums a bit to see if it is 
possible to use python libraries such as matplotlib which I 
have enough experience with, and wish to continue using this 
wonderful library within D. Maybe there are great D graphing 
libraries, but I have zero experience with them.


I cam across PyD and found an example from "Welcome to Quick 
Start with D!"

http://d.readthedocs.io/en/latest/examples.html#plotting-with-matplotlib-python

I have tried to understand the example here and thoroughly as 
possible, to the point of downloading the Github example 
https://github.com/andralex/thenextafterc/tree/master/examples/matplotlib


When I try to compile the app.d script with dmd I get the 
following error


app.d(1): Error: module pyd is in file 'pyd/pyd.d' which cannot 
be read

import path[0] = /Library/D/dmd/src/phobos
import path[1] = /Library/D/dmd/src/druntime/import

I have tried to install PyD with pip and installed version 0.10 
which I think is the same as

https://pypi.python.org/pypi/pyd

But according to dlang https://code.dlang.org/packages/pyd only 
up to version 0.9.9 is supported?


you need to tell the compiler where to look to find pyd (which it 
can't find in '/Library/D/dmd/src/phobos' or 
'/Library/D/dmd/src/druntime/import').
If you are invoking the compiler yourself use the `-I` switch 
(`-Ipath/to/pyd`).
Or if you are using dub (I recommend this) make sure that is is 
in your list of dependencies.


Storing Formatted Array Value

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

Hi All,

Request your help, with the below code I am able to print the 
value of the array without brackects , but can some on help me on 
hot to store this output to a variable


Program:
import std.stdio;
import std.container;

void main()
{
   auto test = Array!string("Test1", "Test2");
   writefln("%(%s, %)",test[]); // output : "Test1", "Test2"

   // Similar like this
   auto res = `writefln("%(%s, %)",test[])`;
   writeln(res);
}

Output of res should look like : "Test1", "Test2" (Without [] 
brackets).



From,
Vino.B




Re: Email validation

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

On Wednesday, 29 November 2017 at 05:22:34 UTC, Dmitry wrote:
On Wednesday, 29 November 2017 at 03:49:56 UTC, codephantom 
wrote:

string domainRequired = "@hotmail.com";

string emailAddress = "vino.bhee...@hotmail.com";

emailAddress.endsWith(domainRequired) ? writeln("domain 
ok")

 : writeln("invalid domain");

Also you need check that only one @ used.


Hi All,

 Thank you, the above code worked.

From,
Vino.B


Python and D (PyD)

2017-11-28 Thread Fat_Umpalumpa via Digitalmars-d-learn
Hello, I have searched these forums a bit to see if it is 
possible to use python libraries such as matplotlib which I have 
enough experience with, and wish to continue using this wonderful 
library within D. Maybe there are great D graphing libraries, but 
I have zero experience with them.


I cam across PyD and found an example from "Welcome to Quick 
Start with D!"

http://d.readthedocs.io/en/latest/examples.html#plotting-with-matplotlib-python

I have tried to understand the example here and thoroughly as 
possible, to the point of downloading the Github example 
https://github.com/andralex/thenextafterc/tree/master/examples/matplotlib


When I try to compile the app.d script with dmd I get the 
following error


app.d(1): Error: module pyd is in file 'pyd/pyd.d' which cannot 
be read

import path[0] = /Library/D/dmd/src/phobos
import path[1] = /Library/D/dmd/src/druntime/import

I have tried to install PyD with pip and installed version 0.10 
which I think is the same as

https://pypi.python.org/pypi/pyd

But according to dlang https://code.dlang.org/packages/pyd only 
up to version 0.9.9 is supported?


Strange error when compiling with dmd, not with ldc

2017-11-28 Thread Fra Mecca via Digitalmars-d-learn

I have this struct:

immutable struct Configuration {
string title;
string baseurl;
string url;
string email;
string author;
string parser;
string target;
string urlFormat;
string urlFormatCmd;

short port;

string[] ignore;
string[] extensions;

@property string toString()
{
auto urlF = (urlFormatCmd ? "url_format_cmd: " ~ 
urlFormatCmd : "") ~ "\n";

return
"title: "~ title ~ "\n" ~
"baseurl: "  ~ baseurl ~ "\n" ~
"url: "  ~ url ~ "\n" ~
"email: "~ email ~ "\n" ~
"author: "   ~ author ~ "\n" ~
"parser: "   ~ parser ~ "\n" ~
"target: "   ~ target ~ "\n" ~
"url_format: "   ~ urlFormat ~ "\n" ~
"ignore: "   ~ to!string(ignore)[1 .. $ - 1] ~ "\n" ~
"extensions: "   ~ to!string(extensions)[1 .. $ - 1] ~ 
"\n" ~

urlF;
}
}

and this function:

void show_config()
{
writef("%s", parse_config(
exists("config.sdl") ? "config.sdl" : 
"").toString);

}


Whenever I compile with ldc2 I get no errors, while with dmd I 
get:


source/configuration.d(105,27): Error: immutable method 
configuration.Configuration.toString is not callable using a 
mutable object



What is the problem?


Re: Web servers in D

2017-11-28 Thread rikki cattermole via Digitalmars-d-learn

On 29/11/2017 5:51 AM, Hasen Judy wrote:

On Tuesday, 12 September 2017 at 12:34:26 UTC, aberba wrote:

On Friday, 25 August 2017 at 05:25:09 UTC, Hasen Judy wrote:

What libraries are people using to run webservers other than vibe.d?

Don't get me wrong I like the async-io aspect of vibe.d but I don't 
like the weird template language and the fact that it caters to mongo 
crowd.


I think for D to a have good web story it needs to appeal to serious 
backend developers, not hipsters who go after fads (mongodb is a fad, 
jade/haml is a fad).


I probably need to combine several libraries, but the features I'm 
looking for are:


- Spawn an HTTP server listening on a port, and routing requests to 
functions/delegates, without hiding the details of the http 
request/response objects (headers, cookies, etc).


- Support for websockets

- Runs delegates in fibers/coroutines

- Basic database connectivity (No "orm" needed; just raw sql).

- When iterating the result set of a sql query, has the ability to 
automatically map each row against a struct, and throw if the 
structure does not match.


- More generally, map any arbitrary object (such as json) to a 
struct. Something like Zewo/Reflection package for swift[0].


[0]: https://github.com/Zewo/Reflection

I feel like Vibe.d satisfies my first 3 requirements, but for the 
rest I will probably have to look for something else.


In 2017, backend developers are more likely to write microservices 
which expose rest/graphQL APIs and put them in dockers containers 
Unless you're a full stack developer, you'll not be using jade/diet 
(at least not enough to be tempted to use something else).


Its still sucks there's no object storage api for D. Are you guys 
still building monolithic web servers?


Sorry this is an incredibly late response.

Come on now, in CURRENT_YEAR people are jumping and this year's fad 
train. I don't want to jump along, thank you very much.


And I don't understand this containers business. As far as I can tell it 
was designed for interpreted languages because they tend to have a lot 
of very specific dependences that are a hell to manage.


If the compiler can produce a statically linked binary, then there's no 
problem that a container would solve here.


Containers are an "easy" way to push your full system over to another's 
servers. It is all about cost. They are cheaper than VM's as they 
require less resources to manage and use.


Re: Web servers in D

2017-11-28 Thread Hasen Judy via Digitalmars-d-learn

On Tuesday, 12 September 2017 at 12:34:26 UTC, aberba wrote:

On Friday, 25 August 2017 at 05:25:09 UTC, Hasen Judy wrote:
What libraries are people using to run webservers other than 
vibe.d?


Don't get me wrong I like the async-io aspect of vibe.d but I 
don't like the weird template language and the fact that it 
caters to mongo crowd.


I think for D to a have good web story it needs to appeal to 
serious backend developers, not hipsters who go after fads 
(mongodb is a fad, jade/haml is a fad).


I probably need to combine several libraries, but the features 
I'm looking for are:


- Spawn an HTTP server listening on a port, and routing 
requests to functions/delegates, without hiding the details of 
the http request/response objects (headers, cookies, etc).


- Support for websockets

- Runs delegates in fibers/coroutines

- Basic database connectivity (No "orm" needed; just raw sql).

- When iterating the result set of a sql query, has the 
ability to automatically map each row against a struct, and 
throw if the structure does not match.


- More generally, map any arbitrary object (such as json) to a 
struct. Something like Zewo/Reflection package for swift[0].


[0]: https://github.com/Zewo/Reflection

I feel like Vibe.d satisfies my first 3 requirements, but for 
the rest I will probably have to look for something else.


In 2017, backend developers are more likely to write 
microservices which expose rest/graphQL APIs and put them in 
dockers containers Unless you're a full stack developer, 
you'll not be using jade/diet (at least not enough to be 
tempted to use something else).


Its still sucks there's no object storage api for D. Are you 
guys still building monolithic web servers?


Sorry this is an incredibly late response.

Come on now, in CURRENT_YEAR people are jumping and this year's 
fad train. I don't want to jump along, thank you very much.


And I don't understand this containers business. As far as I can 
tell it was designed for interpreted languages because they tend 
to have a lot of very specific dependences that are a hell to 
manage.


If the compiler can produce a statically linked binary, then 
there's no problem that a container would solve here.


Re: Email validation

2017-11-28 Thread Dmitry via Digitalmars-d-learn

On Wednesday, 29 November 2017 at 03:49:56 UTC, codephantom wrote:

string domainRequired = "@hotmail.com";

string emailAddress = "vino.bhee...@hotmail.com";

emailAddress.endsWith(domainRequired) ? writeln("domain ok")
 : writeln("invalid domain");

Also you need check that only one @ used.


Re: Email validation

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

On Tuesday, 28 November 2017 at 18:47:06 UTC, Vino wrote:

Hi All,

 Can you please provide me some example on who to validate an 
email address as the document dose not have an example for the 
same


Ex: vino.bhee...@hotmail.com

Conditions :

The domain should contain only "hotmail.com"
The email address should contain the symbol "@"

From,
Vino.B



Here's another nice option I just found.

Interestingly, I had to disable Avast antivirus, otherwise when I 
compile it, Avast thinks the exectuable is 'suspicous' and 
prevents any further access to it...wtf?


// -
module test;

import std.stdio;
import std.algorithm;

/+
CONDITIONS:
- The domain should contain only "hotmail.com"
- The email address should contain the symbol "@"
+/

void main()
{
string domainRequired = "@hotmail.com";

string emailAddress = "vino.bhee...@hotmail.com";

emailAddress.endsWith(domainRequired) ? writeln("domain ok")
 : writeln("invalid domain");

}

// 



Re: Email validation

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

On Tuesday, 28 November 2017 at 22:42:27 UTC, Mike Wey wrote:
isMail only checks the formatting of the email address and 
optionally if the domain has a MX record.




I don't believe MX validation (checkDns) is implemented yet.



Re: Email validation

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

On Tuesday, 28 November 2017 at 18:47:06 UTC, Vino wrote:

Hi All,

 Can you please provide me some example on who to validate an 
email address as the document dose not have an example for the 
same


Ex: vino.bhee...@hotmail.com

Conditions :

The domain should contain only "hotmail.com"
The email address should contain the symbol "@"

From,
Vino.B


test/improve it yourself. but you get the idea

// --

module test;

import std.stdio;
import std.algorithm;

/+
CONDITIONS:
- The domain should contain only "hotmail.com"
- The email address should contain the symbol "@"
+/

void main()
{
string domainRequired = "hotmail.com";

string emailAddress = "vino.bhee...@hotmail.com";

auto checkDomain = findSplitAfter(emailAddress, "@"); // 
requires import std.algorithm


//writeln(checkDomain); // Tuple!(string, 
string)("vino.bheeman@", "hotmail.com")


if (checkDomain[1] == domainRequired)
writeln("domain ok");
else
writeln("invalid domain");


}

// --



Re: Floating point types default to NaN?

2017-11-28 Thread A Guy With a Question via Digitalmars-d-learn
On Wednesday, 29 November 2017 at 01:25:47 UTC, Michael V. 
Franklin wrote:
On Wednesday, 29 November 2017 at 01:24:21 UTC, A Guy With a 
Question wrote:



I was just more curious of the design decisions that were made.


So am I.  I'm trying to get to the heart of in the the PR 
comments.


Mike


That's a lot less code than I would have thought to implement 
that. The comment about phobos was a good one. Just reading 
through it.


Re: Floating point types default to NaN?

2017-11-28 Thread Michael V. Franklin via Digitalmars-d-learn
On Wednesday, 29 November 2017 at 01:24:21 UTC, A Guy With a 
Question wrote:



I was just more curious of the design decisions that were made.


So am I.  I'm trying to get to the heart of in the the PR 
comments.


Mike


Re: Floating point types default to NaN?

2017-11-28 Thread A Guy With a Question via Digitalmars-d-learn
On Tuesday, 28 November 2017 at 20:00:53 UTC, Michael V. Franklin 
wrote:
On Monday, 27 November 2017 at 23:05:55 UTC, Michael V. 
Franklin wrote:


I think I'm going to implement a feature gate to require 
explicit initialization.  It would be better to be strict up 
front and relax it as flow control analysis becomes more 
mature.


Well, I implemented it 
(https://github.com/dlang/dmd/pull/7375), but it's off to a 
pretty rocky start.


Mike


To be honest, I didn't actually expect anyone to act on my 
question. :D

I was just more curious of the design decisions that were made.


Re: Really? -- Error: function `object.Throwable.message` is not nothrow

2017-11-28 Thread A Guy With a Question via Digitalmars-d-learn
On Wednesday, 29 November 2017 at 00:52:41 UTC, A Guy With a 
Question wrote:

.msg worked. I will let you all live.


Thanks!


Re: Really? -- Error: function `object.Throwable.message` is not nothrow

2017-11-28 Thread A Guy With a Question via Digitalmars-d-learn

.msg worked. I will let you all live.


Re: Really? -- Error: function `object.Throwable.message` is not nothrow

2017-11-28 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, November 28, 2017 23:48:06 Adam D. Ruppe via Digitalmars-d-learn 
wrote:
> On Tuesday, 28 November 2017 at 23:41:28 UTC, A Guy With a
>
> Question wrote:
> > What's the clean way to extract the message that passes the
> > nothrow argument? Do I really have to embed another try catch?
>
> I didn't even know it had a `message`... you should be able to
> pull the `.msg` member directly though, which is a simple string
> and not a function at all.
>
> http://dpldocs.info/experimental-docs/object.Throwable.html

I think that message was added recently for the folks at Sociomantic,
because they want to be able to reuse buffers for exception messages rather
than passing them as string like is normally done. So, they can override
message to provide the message instead of using msg. I have no idea why it
wouldn't be nothrow though. That was probably an oversight. Regardless, if
you're not doing anything with overriding message in your own code, then
using msg should work just fine.

- Jonathan M Davis



Re: Really? -- Error: function `object.Throwable.message` is not nothrow

2017-11-28 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 28 November 2017 at 23:41:28 UTC, A Guy With a 
Question wrote:
What's the clean way to extract the message that passes the 
nothrow argument? Do I really have to embed another try catch?


I didn't even know it had a `message`... you should be able to 
pull the `.msg` member directly though, which is a simple string 
and not a function at all.


http://dpldocs.info/experimental-docs/object.Throwable.html


Really? -- Error: function `object.Throwable.message` is not nothrow

2017-11-28 Thread A Guy With a Question via Digitalmars-d-learn
What's the clean way to extract the message that passes the 
nothrow argument? Do I really have to embed another try catch?


Re: Email validation

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

On Tuesday, 28 November 2017 at 19:32:40 UTC, Vino wrote:


 Can you provide me a example, as the link does not have any 
examples.


From,
Vino.B


btw... yes documentation is an acknowledged issue with regards to 
phobos...but..that aside...it can also be useful (and wise) to 
look at the unit tests in the source code.


I'm not sure that simply calling something you don't know 
anything about is such a good idea these days ;-)


...fortunately, we have access to the source - which gets 
installed with dmd.


or you can find it on github.

https://github.com/dlang/phobos




Re: Email validation

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

On 28-11-17 20:32, Vino wrote:

On Tuesday, 28 November 2017 at 18:51:50 UTC, Rene Zwanenburg wrote:

On Tuesday, 28 November 2017 at 18:47:06 UTC, Vino wrote:

Hi All,


You can do this easily using the std.net.isemail module:

https://dlang.org/phobos/std_net_isemail.html


Hi Rene,

  Can you provide me a example, as the link does not have any examples.

From,
Vino.B


isEmail returns a struct with the status of the check.
You can use the valid and domainPart to check if it's a valid email 
address for the hotmail domain.


isMail only checks the formatting of the email address and optionally if 
the domain has a MX record.



```
auto e = isEmail("vino.bhee...@hotmail.com");

if ( e.valid && e.domainPart == "hotmail.com" )
...
```

--
Mike Wey


Re: Floating point types default to NaN?

2017-11-28 Thread Michael V. Franklin via Digitalmars-d-learn
On Monday, 27 November 2017 at 23:05:55 UTC, Michael V. Franklin 
wrote:


I think I'm going to implement a feature gate to require 
explicit initialization.  It would be better to be strict up 
front and relax it as flow control analysis becomes more mature.


Well, I implemented it (https://github.com/dlang/dmd/pull/7375), 
but it's off to a pretty rocky start.


Mike




Re: Email validation

2017-11-28 Thread Vino via Digitalmars-d-learn
On Tuesday, 28 November 2017 at 18:51:50 UTC, Rene Zwanenburg 
wrote:

On Tuesday, 28 November 2017 at 18:47:06 UTC, Vino wrote:

Hi All,


You can do this easily using the std.net.isemail module:

https://dlang.org/phobos/std_net_isemail.html


Hi Rene,

 Can you provide me a example, as the link does not have any 
examples.


From,
Vino.B


Problems with ctRegex

2017-11-28 Thread crimaniak via Digitalmars-d-learn

First problem: it doesn't understand enums, it seems to be a bug:

```
enum TopicMask : string
{
divider = "/",
oneLevelMask = "+",
multiLevelMask = "#",
system = "$",
level = "[^"~divider~oneLevelMask~multiLevelMask~"]*",
publishMask = "^("~divider~"|"~level~")+$"
}


bool topicIsValid(string topic) pure
{
import std.regex;
auto mask = ctRegex!(TopicMask.publishMask);
return !topic.matchFirst(mask).empty;
}

```

result:

/usr/include/dmd/phobos/std/regex/package.d(376,20): Error: 
template std.array.Appender!(TopicMask).Appender.put cannot 
deduce function from argument types !()(TopicMask), candidates 
are:
/usr/include/dmd/phobos/std/array.d(2983,10):
std.array.Appender!(TopicMask).Appender.put(U)(U item) if 
(canPutItem!U)
/usr/include/dmd/phobos/std/array.d(3011,10):
std.array.Appender!(TopicMask).Appender.put(Range)(Range items) 
if (canPutConstRange!Range)
/usr/include/dmd/phobos/std/array.d(3020,10):
std.array.Appender!(TopicMask).Appender.put(Range)(Range items) 
if (canPutRange!Range)
/usr/include/dmd/phobos/std/regex/package.d(387,15): Error: 
cannot implicitly convert expression `app.data()` of type 
`string` to `TopicMask`
/usr/include/dmd/phobos/std/regex/package.d(422,19): Error: 
template instance std.regex.internal.parser.Parser!(TopicMask, 
CodeGen) does not match template declaration Parser(R, Generator) 
if (isForwardRange!R && is(ElementType!R : dchar))
/usr/include/dmd/phobos/std/regex/package.d(393,25): Error: 
template instance std.regex.regexImpl!(TopicMask) error 
instantiating
/usr/include/dmd/phobos/std/regex/package.d(401,17):
instantiated from here: regex!(TopicMask)
/usr/include/dmd/phobos/std/regex/package.d(431,19):
instantiated from here: regex!(TopicMask)
/usr/include/dmd/phobos/std/regex/package.d(453,54):
instantiated from here: ctRegexImpl!("^(/|[^/+#]*)+$", [])
source/mqttd/topic.d(48,14):instantiated from here: 
ctRegex!("^(/|[^/+#]*)+$", [])



If I change ctRegex!(TopicMask.publishMask) to 
ctRegex!("^(/|[^/+#]*)+$") I run into next error:


source/mqttd/topic.d(48,26): Error: pure function 
'mqttd.topic.topicIsValid' cannot call impure function 
'std.regex.matchFirst!(string, StaticRegex!char).matchFirst'
source/mqttd/topic.d(48,26): Error: pure function 
'mqttd.topic.topicIsValid' cannot call impure destructor 
'std.regex.Captures!(string, ulong).Captures.~this'



Is there any change to use regex inside or pure function? I just 
need some pure bool test() method to test string against the mask.




Re: Email validation

2017-11-28 Thread Rene Zwanenburg via Digitalmars-d-learn

On Tuesday, 28 November 2017 at 18:47:06 UTC, Vino wrote:

Hi All,


You can do this easily using the std.net.isemail module:

https://dlang.org/phobos/std_net_isemail.html



Email validation

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

Hi All,

 Can you please provide me some example on who to validate an 
email address as the document dose not have an example for the 
same


Ex: vino.bhee...@hotmail.com

Conditions :

The domain should contain only "hotmail.com"
The email address should contain the symbol "@"

From,
Vino.B


Re: Reading a File

2017-11-28 Thread Vino via Digitalmars-d-learn
On Tuesday, 28 November 2017 at 18:34:51 UTC, Steven 
Schveighoffer wrote:

On 11/28/17 1:10 PM, Vino wrote:

Hi All,

   Need your help, I have file which contains 3 lines, I need 
to ignore the line's which does not have the sign "=", in the 
blow example the 3rd  line(FileName2) and store the result in 
a array, I was able to ignore the line which contains '#" and 
empty lines , but need to help on how to filter the lines 
which does not have the sign "=".


string ConfigFile = Test.txt
#This is a Sample File
FileName1 = test1.txt
FileName2

auto PLines = 
Array!string(File(ConfigFile).byLineCopy().filter!(line => 
!line.all!isWhite && line[0].isAlpha));




&& line.canFind("=")

https://dlang.org/phobos/std_algorithm_searching.html#.canFind

-Steve


Hi Steve,

 Thank you very much.

From,
Vino.B


Re: Reading a File

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

On 11/28/17 1:10 PM, Vino wrote:

Hi All,

   Need your help, I have file which contains 3 lines, I need to ignore 
the line's which does not have the sign "=", in the blow example the 
3rd  line(FileName2) and store the result in a array, I was able to 
ignore the line which contains '#" and empty lines , but need to help on 
how to filter the lines which does not have the sign "=".


string ConfigFile = Test.txt
#This is a Sample File
FileName1 = test1.txt
FileName2

auto PLines = Array!string(File(ConfigFile).byLineCopy().filter!(line => 
!line.all!isWhite && line[0].isAlpha));




&& line.canFind("=")

https://dlang.org/phobos/std_algorithm_searching.html#.canFind

-Steve


Reading a File

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

Hi All,

  Need your help, I have file which contains 3 lines, I need to 
ignore the line's which does not have the sign "=", in the blow 
example the 3rd  line(FileName2) and store the result in a array, 
I was able to ignore the line which contains '#" and empty lines 
, but need to help on how to filter the lines which does not have 
the sign "=".


string ConfigFile = Test.txt
#This is a Sample File
FileName1 = test1.txt
FileName2

auto PLines = 
Array!string(File(ConfigFile).byLineCopy().filter!(line => 
!line.all!isWhite && line[0].isAlpha));


From,
Vino.B


Re: R.filter!(..).sort!(..)

2017-11-28 Thread Timoses via Digitalmars-d-learn
On Tuesday, 28 November 2017 at 14:04:40 UTC, Steven 
Schveighoffer wrote:

Would be an awesome project to add to D.


Oh yes, it sounds yummy..


Re: Basic questions about D lang?

2017-11-28 Thread Ali Çehreli via Digitalmars-d-learn

On 11/28/2017 05:51 AM, Jayam wrote:

> Can we compile our program to multi platform?

Most definitely! D is great in multi-threaded programming. (I hope that 
was the question. :) )


Ali



Re: Basic questions about D lang?

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

On 11/28/17 8:52 AM, Jayam wrote:

On Tuesday, 28 November 2017 at 13:42:05 UTC, Stefan Koch wrote:

On Tuesday, 28 November 2017 at 13:39:11 UTC, Jayam wrote:

Is D language open source?
Do this have GUI Desktop application support ?
Do this have web api support ?
Can we compile our program to multi program ?


yes
yes some (dlang-ui for example)
yes some (vibe.d or arsd)
I don't know what you mean with that


Thanks.
Can we compile our program to multi platform?


D supports several platforms:

https://wiki.dlang.org/Compilers

-Steve


Re: R.filter!(..).sort!(..)

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

On 11/28/17 8:57 AM, Arjan wrote:

On Tuesday, 28 November 2017 at 13:24:09 UTC, Steven Schveighoffer wrote:

On 11/28/17 8:10 AM, Arjan wrote:

[...]


The library is correctly telling you that your filtered range is not 
random access. It can't be, because it lazily applies the filter (that 
is, it filters on each element as you popFront them). So how can it 
know what the e.g. 3rd element is, if you haven't run any filters yet?


The array version works because you are applying the filter completely 
and storing the results elsewhere in one step.




Well I would have liked an error msg something like: 
isRandomAccessRange!Range for Range=.. failed! Or unable to sort!() a 
lazy Range.


Sure, the error messages could be more specific about WHY it's failing. 
This has been discussed many times, but no action has been taken.


Would be an awesome project to add to D.

-Steve


Re: R.filter!(..).sort!(..)

2017-11-28 Thread Arjan via Digitalmars-d-learn
On Tuesday, 28 November 2017 at 13:24:09 UTC, Steven 
Schveighoffer wrote:

On 11/28/17 8:10 AM, Arjan wrote:

[...]


The library is correctly telling you that your filtered range 
is not random access. It can't be, because it lazily applies 
the filter (that is, it filters on each element as you popFront 
them). So how can it know what the e.g. 3rd element is, if you 
haven't run any filters yet?


The array version works because you are applying the filter 
completely and storing the results elsewhere in one step.


-Steve


Well I would have liked an error msg something like: 
isRandomAccessRange!Range for Range=.. failed! Or unable to 
sort!() a lazy Range.


Re: Basic questions about D lang?

2017-11-28 Thread Jayam via Digitalmars-d-learn

On Tuesday, 28 November 2017 at 13:42:05 UTC, Stefan Koch wrote:

On Tuesday, 28 November 2017 at 13:39:11 UTC, Jayam wrote:

Is D language open source?
Do this have GUI Desktop application support ?
Do this have web api support ?
Can we compile our program to multi program ?


yes
yes some (dlang-ui for example)
yes some (vibe.d or arsd)
I don't know what you mean with that


Thanks.
Can we compile our program to multi platform?


Re: Basic questions about D lang?

2017-11-28 Thread Jayam via Digitalmars-d-learn
On Tuesday, 28 November 2017 at 13:42:08 UTC, rikki cattermole 
wrote:

On 28/11/2017 1:39 PM, Jayam wrote:

Is D language open source?


Yes 100%


Do this have GUI Desktop application support ?


Sure but probably not to the level you expect.


Do this have web api support ?


Ugh what? Be more specific.


Can we compile our program to multi program ?


Okay that definitely makes no sense.

Do you mean can we cross compile to other architectures other 
than the host?


Thanks.
Can we compile our program to multi platform?


Re: Basic questions about D lang?

2017-11-28 Thread rikki cattermole via Digitalmars-d-learn

On 28/11/2017 1:39 PM, Jayam wrote:

Is D language open source?


Yes 100%


Do this have GUI Desktop application support ?


Sure but probably not to the level you expect.


Do this have web api support ?


Ugh what? Be more specific.


Can we compile our program to multi program ?


Okay that definitely makes no sense.

Do you mean can we cross compile to other architectures other than the host?


Re: Basic questions about D lang?

2017-11-28 Thread Stefan Koch via Digitalmars-d-learn

On Tuesday, 28 November 2017 at 13:39:11 UTC, Jayam wrote:

Is D language open source?
Do this have GUI Desktop application support ?
Do this have web api support ?
Can we compile our program to multi program ?


yes
yes some (dlang-ui for example)
yes some (vibe.d or arsd)
I don't know what you mean with that


Basic questions about D lang?

2017-11-28 Thread Jayam via Digitalmars-d-learn

Is D language open source?
Do this have GUI Desktop application support ?
Do this have web api support ?
Can we compile our program to multi program ?



Re: R.filter!(..).sort!(..)

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

On 11/28/17 8:10 AM, Arjan wrote:

When applying a sort!() on a filtered range I get this compiler error:

Error: template std.algorithm.sorting.sort cannot deduce function from 
argument types !((a, b) => a.name < b.name)(FilterResult!(__lambda3, 
RangeT!(Array!(IssueType, candidates are:
C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm\sorting.d(1851,1):
std.algorithm.sorting.sort(alias less = "a < b", SwapStrategy ss = 
SwapStrategy.unstable, Range)(Range r) if ((ss == SwapStrategy.unstable 
&& (hasSwappableElements!Range || hasAssignableElements!Range) || ss != 
SwapStrategy.unstable && hasAssignableElements!Range) && 
isRandomAccessRange!Range && hasSlicing!Range && hasLength!Range)


But it seems the problem is with the filter!() result not being a 
isRandomAccessRange!Range because:
R.filter!(..).array.sort!(..) just works (by copying the filter results 
in a array).


Iaw is the compiler error msg wrong? Or i'm I wrong?


The library is correctly telling you that your filtered range is not 
random access. It can't be, because it lazily applies the filter (that 
is, it filters on each element as you popFront them). So how can it know 
what the e.g. 3rd element is, if you haven't run any filters yet?


The array version works because you are applying the filter completely 
and storing the results elsewhere in one step.


-Steve


Re: R.filter!(..).sort!(..)

2017-11-28 Thread Adam D. Ruppe via Digitalmars-d-learn

On Tuesday, 28 November 2017 at 13:10:15 UTC, Arjan wrote:

Iaw is the compiler error msg wrong? Or i'm I wrong?


filter isn't random access because it doesn't even know how many 
elements are in there, much less where they are, until it loops 
through and does the comparisons to know which items pass the 
filter.


The .array call will buffer it and also evaluate how many items 
are actually still there after the filter, and sort uses that 
buffer too.


R.filter!(..).sort!(..)

2017-11-28 Thread Arjan via Digitalmars-d-learn
When applying a sort!() on a filtered range I get this compiler 
error:


Error: template std.algorithm.sorting.sort cannot deduce function 
from argument types !((a, b) => a.name < 
b.name)(FilterResult!(__lambda3, RangeT!(Array!(IssueType, 
candidates are:

C:\D\dmd2\windows\bin\..\..\src\phobos\std\algorithm\sorting.d(1851,1):std.algorithm.sorting.sort(alias less = "a < 
b", SwapStrategy ss = SwapStrategy.unstable, Range)(Range r) if ((ss == SwapStrategy.unstable && 
(hasSwappableElements!Range || hasAssignableElements!Range) || ss != SwapStrategy.unstable && hasAssignableElements!Range) 
&& isRandomAccessRange!Range && hasSlicing!Range && hasLength!Range)

But it seems the problem is with the filter!() result not being a 
isRandomAccessRange!Range because:
R.filter!(..).array.sort!(..) just works (by copying the filter 
results in a array).


Iaw is the compiler error msg wrong? Or i'm I wrong?





Re: D program in Windows Task Scheduler.

2017-11-28 Thread rjframe via Digitalmars-d-learn
On Tue, 28 Nov 2017 09:44:39 +, Vino wrote:

> Hi All,
> 
>   I have small D program which run's perfectly when i run it
> manually, but when I schedule the same via windows task scheduler and
> choose the option "Run whether user is logged on or not" the program
> does not execute, the task scheduler job log return code
> 4294967295(Invalid argument). SO request you help on this.

You're not using getopt in the sample; if you comment that line out, do 
you still have the problem?

How are you passing arguments in Task Scheduler? You should be using the 
textbox for arguments, not the same one the application is passed in.
Program/script: test.exe
Add arguments: dryrun, run


If that's correct, create a batch file that takes no arguments and calls 
your application and try running the batch file via Task Scheduler. If 
that fails, the application is probably trying to do something it doesn't 
have permission to do. If it succeeds, the task command is probably not 
set up correctly.

--Ryan


Re: Tried C++ to D. Wrong result.

2017-11-28 Thread Dmitry via Digitalmars-d-learn

On Tuesday, 28 November 2017 at 09:01:47 UTC, Temtaime wrote:

https://pastebin.com/xJXPBh0n
Converted it and it works as expected.

What did you use for it?
In future I'll be needed to convert some more C++ code.

P.S. /And it works wrong, because uses unsafe pointer (ubyte 
*image). So, it takes wrong values (Blue of the next pixel 
instead of Alpha of the current pixel). Same with original code./


P.P.S. Anyway, I already found all things I did wrong. But also I 
found in your code that there is `swap` function, didn't know it. 
Thank you!





D program in Windows Task Scheduler.

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

Hi All,

 I have small D program which run's perfectly when i run it 
manually, but when I schedule the same via windows task scheduler 
and choose the option "Run whether user is logged on or not" the 
program does not execute, the task scheduler job log return code 
4294967295(Invalid argument). SO request you help on this.


Execution Steps
test.exe 

Option: run , dryrun  ,help

Example Execution : test.exe dryrun
Program:
import std.stdio;
import std.getopt;
import std.path;
import core.stdc.stdlib: exit;

void Test1(string Step) {
writeln("This is Test1 :", Step);
}
void Test2() {
writeln("This is Test2");
}
void Test3() {
writeln("This is Help");
}

void main (string[] args) {
if (args.length <= 1 || args.length > 2 ) { writeln("No Arguments 
Provided"); exit(-1); }

string op = args[1];
try {
getopt(args, std.getopt.config.caseInsensitive, 
std.getopt.config.stopOnFirstNonOption);

 switch (op) {
case "dryrun" , "run" :
auto Step = op;
Test1(Step);
Test2;
break;
case "help" :
Test3;
break;
default :
 writefln("Unknown operation");
}
} catch (Exception exc)
	{ writefln("Error processing command line arguments: %s", 
exc.msg);}

}

From,
Vino.B


Re: Tried C++ to D. Wrong result.

2017-11-28 Thread Temtaime via Digitalmars-d-learn

On Tuesday, 28 November 2017 at 06:46:18 UTC, Dmitry wrote:

On Monday, 27 November 2017 at 19:01:28 UTC, Ali Çehreli wrote:
P.S. I think you have an unnecessary 'ref' on the D version 
because a slice is already a reference to elements:

Fixed, thank you.


https://pastebin.com/xJXPBh0n
Converted it and it works as expected.