Re: how to compile D programs without console window

2018-07-14 Thread Flaze07 via Digitalmars-d-learn

On Sunday, 15 July 2018 at 01:20:25 UTC, evilrat wrote:

...
"lflags": [ "/SUBSYSTEM:windows" ],
...


didn't know that, thank you




Re: @safe - why does this compile?

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

On 7/14/18 2:50 AM, Timoses wrote:

On Friday, 13 July 2018 at 22:17:59 UTC, Dukc wrote:

On Friday, 13 July 2018 at 13:52:27 UTC, Timoses wrote:

I suppose this is another good example of how casting can be dangerous?

E.g. also:

    immutable int i = 3;
    int* j = cast(int*)
    assert(i == 3);
*j = 4;
    assert(j == ); // data occupies same address space
    assert(i == 3 && *j == 4); // yet the values differ


No, casting classes to their subclasses is not dangerous to program 
integrity, because it is checked. It is just a regular bug that 
terminates the program when encountered.


But casting away immutable can break program integrity as your example 
demonstrates. For that reason the compiler won't let you do that if 
you wrap that code in @safe, unlike the class cast.


Thanks for the explanation. Only read the function safety chapter in 
depth after posting this : D.


Still, is `cast`ing seen as something "dangerous" or as something that 
should only be done as a last resort? Should std.conv : to be prioritized?


Well, std.conv.to is going to throw if it doesn't dynamically convert. 
So it depends on the behavior you want. But yeah, if you know it's going 
to work, you probably want to do std.conv.to, it's safer.


Just FYI, it's kind of bad that you have to use cast here, because cast 
isn't going to distinguish between dynamic casting and const casting. 
It's kind of a problem in D in general. We don't have C++ niceties like 
const_cast etc.


-Steve


Re: how to compile D programs without console window

2018-07-14 Thread evilrat via Digitalmars-d-learn

On Saturday, 14 July 2018 at 09:43:48 UTC, Flaze07 wrote:
On Saturday, 14 July 2018 at 09:39:21 UTC, rikki cattermole 
wrote:

If you're using dub, throw them into lflags and remove the -L.

https://forum.dlang.org/post/gmcsxgfsfnwllploo...@forum.dlang.org
hmm, for some unknown reason it says that it is unable to find 
SUBSYSTEM:windows.lib


/ (slash) is the part of a linker switch, /SUBSYSTEM:windows
so in dub.json it will look like

...
"lflags": [ "/SUBSYSTEM:windows" ],
...


Is there any tool that will auto publish my changes.

2018-07-14 Thread Venkat via Digitalmars-d-learn
I am writing a simple vibe.d app. The following is what I do 
right now.


- I make changes.
- build
- Restart the server.

Is there any tool that will auto publish my changes as I save 
them ? I am using Visual Studio Code.


Thanks
Venkat


Re: Find out druntime/import and phobos folder on Linux

2018-07-14 Thread Mike Franklin via Digitalmars-d-learn

On Saturday, 14 July 2018 at 19:04:01 UTC, Andre Pany wrote:

Somehow also the DMD executable needs to know which 
Phobos/DRuntime it should use.

How does DMD is working here? Maybe I can do the same...


DMD determines default import and library paths from the dmd.conf 
file typically at /etc/dmd.conf.


Mike



Re: Find out druntime/import and phobos folder on Linux

2018-07-14 Thread Anonymouse via Digitalmars-d-learn

On Saturday, 14 July 2018 at 17:19:20 UTC, Andre Pany wrote:
Is there a way to find out both paths based on the dmd 
executable folder?


What I found out so far, these paths are not always correct:
/usr/include/dmd/druntime/import
/usr/include/dmd/phobos


Arch Linux and derivatives keep them under 
/usr/include/dlang/{dmd,gdc,ldc}/*


You may have to hardcode some common paths and try them in each 
in turn. I'm happy to be proven wrong here though.


Re: Find out druntime/import and phobos folder on Linux

2018-07-14 Thread Andre Pany via Digitalmars-d-learn

On Saturday, 14 July 2018 at 19:00:56 UTC, Anonymouse wrote:

On Saturday, 14 July 2018 at 17:19:20 UTC, Andre Pany wrote:
Is there a way to find out both paths based on the dmd 
executable folder?


What I found out so far, these paths are not always correct:
/usr/include/dmd/druntime/import
/usr/include/dmd/phobos


Arch Linux and derivatives keep them under 
/usr/include/dlang/{dmd,gdc,ldc}/*


You may have to hardcode some common paths and try them in each 
in turn. I'm happy to be proven wrong here though.


Somehow also the DMD executable needs to know which 
Phobos/DRuntime it should use.

How does DMD is working here? Maybe I can do the same...

Kind regards
André


Re: Check whether a range is empty

2018-07-14 Thread Ali Çehreli via Digitalmars-d-learn

First, please show us code that demonstrates the issue.

On 07/14/2018 07:47 AM, vino.B wrote:

>The reason it never prints the text "Empty" is that the out of the
> "r" is just an empty array.
>
> OUTPUT:
> []
> []

If that's the output of r, then r is not empty but has two elements and 
those elements are likely arrays. If they are in fact arrays, them being 
empty does not change r: it still has two elements.


If you want to treat the range as empty when all its elements are empty, 
then perhaps your problem needs std.algorithm.joiner. The following 
program demonstrates your issue with the first assert and the fix with 
the second assert:


import std.algorithm;
import std.range;

void main() {
int[][] r = [ [], [] ];
assert(!r.empty);
auto joined_r = r.joiner;
assert(joined_r.empty);
}

joiner joins elements that are ranges themselves. For example, joiner([ 
[1], [2] ]) is equal to [ 1, 2 ].


Ali



Find out druntime/import and phobos folder on Linux

2018-07-14 Thread Andre Pany via Digitalmars-d-learn

Hi,

The IntelliJ D Language plugin has support for D-scanner and DCD. 
Both tools needs to know the paths to druntime/import and Phobos 
source folder.
In IntelliJ you set the path to the folder where dmd binary is 
located. Based on this information on Windows and MacOS it is 
possible to determine the paths.


The code can be found here
https://github.com/intellij-dlanguage/intellij-dlanguage/blob/develop/src/main/java/io/github/intellij/dlanguage/codeinsight/dcd/DCDCompletionServer.java#L180

I want to provide a fix that the paths are also automatically 
determined on Linux correctly but I do not have much Linux 
experience.


Is there a way to find out both paths based on the dmd executable 
folder?


What I found out so far, these paths are not always correct:
/usr/include/dmd/druntime/import
/usr/include/dmd/phobos

Kind regards
Andre


Re: Check whether a range is empty

2018-07-14 Thread vino.B via Digitalmars-d-learn

On Saturday, 14 July 2018 at 14:28:52 UTC, vino.B wrote:
On Friday, 13 July 2018 at 19:45:03 UTC, Steven Schveighoffer 
wrote:

On 7/13/18 3:29 PM, vino.B wrote:

 [...]



Well, empty is how you detect whether any range is empty, and 
as far as ranges are concerned, your code is correctly 
checking for empty.


A couple comments:

1. Why are you using chain with a single parameter? That just 
returns its parameter.

2. You may want to try grabbing the range ONCE. i.e.:

auto r = PFresult.toRange;
if(!r.empty)
{
   foreach(i; r) ...
}

I'm not familiar with how taskPool works, so I don't know the 
real answer.


-Steve


Hi Steve,

 i Tried your method no luck, it just prints blank lines.

From,
Vino.B


Hi Steve,

  The reason it never prints the text "Empty" is that the out of 
the "r" is just an empty array.


OUTPUT:
[]
[]

From,
Vino.B


Re: Check whether a range is empty

2018-07-14 Thread vino.B via Digitalmars-d-learn
On Friday, 13 July 2018 at 19:45:03 UTC, Steven Schveighoffer 
wrote:

On 7/13/18 3:29 PM, vino.B wrote:

 [...]



Well, empty is how you detect whether any range is empty, and 
as far as ranges are concerned, your code is correctly checking 
for empty.


A couple comments:

1. Why are you using chain with a single parameter? That just 
returns its parameter.

2. You may want to try grabbing the range ONCE. i.e.:

auto r = PFresult.toRange;
if(!r.empty)
{
   foreach(i; r) ...
}

I'm not familiar with how taskPool works, so I don't know the 
real answer.


-Steve


Hi Steve,

 i Tried your method no luck, it just prints blank lines.

From,
Vino.B


Re: Call method with Variant array as parameters

2018-07-14 Thread Andre Pany via Digitalmars-d-learn

On Saturday, 14 July 2018 at 11:37:20 UTC, Timoses wrote:

On Saturday, 14 July 2018 at 11:08:21

How about this?


import std.variant: Variant;
import std.traits : isCallable;

class Foo
{
void bar(string s, long l)
{
import std.stdio : writeln;
writeln(s); writeln(l);
}
}

void call(T)(T fun, in Variant[] args)
 if (isCallable!fun)
{
import std.traits : Parameters;
alias Params = Parameters!fun;

Params params;
static foreach(i, param; params)
{
if (auto p = args[i].peek!(Params[i]))
{
param = *p;
}
// perhaps create a warning if peeking was 
unsuccessful...

}
fun(params);
}

unittest
{
Foo foo = new Foo();
Variant[] args = [Variant("Hello"), Variant(42L)];
call(, args);
}


Thank you so much!

Kind regards
Andre



Re: Call method with Variant array as parameters

2018-07-14 Thread Timoses via Digitalmars-d-learn

On Saturday, 14 July 2018 at 11:08:21 UTC, Andre Pany wrote:

Hi,

I have a class with methods and I want to call a method by 
using a variant array.
The length of the array and the types exactly fits the method 
signature.


In the last line of main you see the coding which should be 
generated.
I need some coding which looks at the signature of bar and uses 
this information

to create "(args[0].get!string, args[1].get!long)".

I think it is possible with string mixins, but is there some 
better way?

Maybe a staticMap?

class Foo
{
void bar(string s, long l) {}
}

void main()
{
import std.variant: Variant;

Foo foo = new Foo();

Variant[] args = [Variant("Hello"), Variant(42)];
__traits(getMember, foo, "bar")(args[0].get!string, 
args[1].get!long);

}

Kind regards
André


How about this?


import std.variant: Variant;
import std.traits : isCallable;

class Foo
{
void bar(string s, long l)
{
import std.stdio : writeln;
writeln(s); writeln(l);
}
}

void call(T)(T fun, in Variant[] args)
 if (isCallable!fun)
{
import std.traits : Parameters;
alias Params = Parameters!fun;

Params params;
static foreach(i, param; params)
{
if (auto p = args[i].peek!(Params[i]))
{
param = *p;
}
// perhaps create a warning if peeking was unsuccessful...
}
fun(params);
}

unittest
{
Foo foo = new Foo();
Variant[] args = [Variant("Hello"), Variant(42L)];
call(, args);
}


Call method with Variant array as parameters

2018-07-14 Thread Andre Pany via Digitalmars-d-learn

Hi,

I have a class with methods and I want to call a method by using 
a variant array.
The length of the array and the types exactly fits the method 
signature.


In the last line of main you see the coding which should be 
generated.
I need some coding which looks at the signature of bar and uses 
this information

to create "(args[0].get!string, args[1].get!long)".

I think it is possible with string mixins, but is there some 
better way?

Maybe a staticMap?

class Foo
{
void bar(string s, long l) {}
}

void main()
{
import std.variant: Variant;

Foo foo = new Foo();

Variant[] args = [Variant("Hello"), Variant(42)];
__traits(getMember, foo, "bar")(args[0].get!string, 
args[1].get!long);

}

Kind regards
André


Re: how to compile D programs without console window

2018-07-14 Thread Flaze07 via Digitalmars-d-learn

On Saturday, 14 July 2018 at 09:39:21 UTC, rikki cattermole wrote:

If you're using dub, throw them into lflags and remove the -L.

https://forum.dlang.org/post/gmcsxgfsfnwllploo...@forum.dlang.org
hmm, for some unknown reason it says that it is unable to find 
SUBSYSTEM:windows.lib






Re: how to compile D programs without console window

2018-07-14 Thread rikki cattermole via Digitalmars-d-learn

On 14/07/2018 9:32 PM, Flaze07 wrote:
how do you compile a D programs without a console window ? I found this 
link
https://wiki.dlang.org/D_for_Win32 I know that you need .def file, but 
how do you link to .def ?


WinAPI:

FreeConsole();

Optlink linker (default for 32bit):

-L/SUBSYSTEM:windows

MSVC linker:

-L/SUBSYSTEM:windows -L/ENTRY:mainCRTStartup


If you're using dub, throw them into lflags and remove the -L.

https://forum.dlang.org/post/gmcsxgfsfnwllploo...@forum.dlang.org


how to compile D programs without console window

2018-07-14 Thread Flaze07 via Digitalmars-d-learn
how do you compile a D programs without a console window ? I 
found this link
https://wiki.dlang.org/D_for_Win32 I know that you need .def 
file, but how do you link to .def ?


Re: @safe - why does this compile?

2018-07-14 Thread Timoses via Digitalmars-d-learn

On Friday, 13 July 2018 at 22:17:59 UTC, Dukc wrote:

On Friday, 13 July 2018 at 13:52:27 UTC, Timoses wrote:
I suppose this is another good example of how casting can be 
dangerous?


E.g. also:

immutable int i = 3;
int* j = cast(int*)
assert(i == 3);
*j = 4;
assert(j == ); // data occupies same address space
assert(i == 3 && *j == 4); // yet the values differ


No, casting classes to their subclasses is not dangerous to 
program integrity, because it is checked. It is just a regular 
bug that terminates the program when encountered.


But casting away immutable can break program integrity as your 
example demonstrates. For that reason the compiler won't let 
you do that if you wrap that code in @safe, unlike the class 
cast.


Thanks for the explanation. Only read the function safety chapter 
in depth after posting this : D.


Still, is `cast`ing seen as something "dangerous" or as something 
that should only be done as a last resort? Should std.conv : to 
be prioritized?


Re: Orange not working?

2018-07-14 Thread Timoses via Digitalmars-d-learn

On Friday, 13 July 2018 at 21:38:18 UTC, JN wrote:


I'm curious, are the tests in any way OS specific? I see the 
tests are passing, but trying the latest DMD on Windows and 
orange v2.0.0, when I add "@nonSerialized" to a struct member, 
I get this:


C:\Users\jacek\Desktop\test_orange>dub run
Performing "debug" build using C:\D\dmd2\windows\bin\dmd.exe 
for x86.

orange 2.0.0: target for configuration "" is up to date.
test_orange ~master: building configuration "application"...
..\..\AppData\Local\dub\packages\orange-2.0.0\orange\orange\serialization\Serializer.d(1504,13):
 Warning: statement is not reachable
..\..\AppData\Local\dub\packages\orange-2.0.0\orange\orange\serialization\Serializer.d(1510,17):
 Warning: statement is not reachable
..\..\AppData\Local\dub\packages\orange-2.0.0\orange\orange\serialization\Serializer.d(1512,13):
 Warning: statement is not reachable
..\..\AppData\Local\dub\packages\orange-2.0.0\orange\orange\serialization\Serializer.d(1514,13):
 Warning: statement is not reachable
C:\D\dmd2\windows\bin\dmd.exe failed with exit code 1.


Wasn't aware of the `buildRequirements "silenceWarnings"` switch 
in dub.sdl.


Now there should hopefully be no more warnings with below PR.

https://github.com/jacob-carlborg/orange/pull/51

Could perhaps bump it to 2.0.1 ? @Jacob