Re: Function parameters UDAs

2018-11-14 Thread Radu via Digitalmars-d-learn
On Wednesday, 14 November 2018 at 18:05:55 UTC, Adam D. Ruppe 
wrote:

On Wednesday, 14 November 2018 at 16:28:19 UTC, Radu wrote:
Looks like that there is no easy way to extract a function 
parameters UDA list.


Indeed, the only way I can find is kinda crazy:

---
void foo(int f, @("test") string s) {}

void main() {
static if(is(typeof(foo) Params == __parameters))
pragma(msg, __traits(getAttributes, 
Params[1..2])); // get the second param

}
---


So, the process is:

1) alias the params with the static if + is() statement (this 
is what std.traits.Parameters does internally)


2) slice the params! using params[0] will not work, but 
params[0 .. 1] will.


3) get the attributes using the language function


Yes, that does the trick, thanks!


Re: Windows Service

2018-11-14 Thread Thomas via Digitalmars-d-learn

On Thursday, 15 November 2018 at 04:45:26 UTC, Soulsbane wrote:

On Wednesday, 14 November 2018 at 19:38:08 UTC, Thomas wrote:

Hi,

I want to run a D program as a Windows service. After 
googl'in, I only found a very old project on github:

https://github.com/tylerjensen/WindowsServiceInD

Unfortunately, I wasn't able to compile it successfully.
Does anybody know of newer approaches or even a template to 
start from?


Thanks in advance,
Thomas


There is https://code.dlang.org/packages/daemonize
I've only played with it a little on the Linux side so I'm not 
sure how good the windows service implementation is.


I have just successfully compiled and started the hello-world 
example. It works (after fixing a small error) in Windows as well.

Thanks a lot!



Vibe throw link error

2018-11-14 Thread greatsam4sure via Digitalmars-d-learn
Vibe.d 0.8.4 throw link error with dmd-2.08.0 and newer on 
windows 10. What is the what out. In dub package register, it was 
said that vibe 0.8.4 works with dmd 2.08.0 and old version but in 
my case it does not work


looking forward for help


Re: Windows Service

2018-11-14 Thread Soulsbane via Digitalmars-d-learn

On Wednesday, 14 November 2018 at 19:38:08 UTC, Thomas wrote:

Hi,

I want to run a D program as a Windows service. After googl'in, 
I only found a very old project on github:

https://github.com/tylerjensen/WindowsServiceInD

Unfortunately, I wasn't able to compile it successfully.
Does anybody know of newer approaches or even a template to 
start from?


Thanks in advance,
Thomas


There is https://code.dlang.org/packages/daemonize
I've only played with it a little on the Linux side so I'm not 
sure how good the windows service implementation is.


Re: Could not setup D extension on vs code

2018-11-14 Thread greatsam4sure via Digitalmars-d-learn

On Wednesday, 14 November 2018 at 19:28:44 UTC, WebFreak001 wrote:
On Wednesday, 14 November 2018 at 13:20:31 UTC, greatsam4sure 
wrote:

[...]


Hi,

thanks for the report, I tagged a new version of workspace-d 
which will fix this issue.


Simply reload vscode and let it rebuild to fix.

Issue was: for a long time dfmt didn't get a new tagged release 
and wasn't compatible with the dscanner and libdparse version I 
used anymore, so I changed it to use ~master instead. Since a 
few days it has been tagged and it was added to workspace-d 
~master but serve-d still uses the latest tagged release.


So as dfmt now got updated to an even newer libdparse, the 
other components don't match that libdparse version anymore and 
now dfmt is too new for it...


It's a real pain that you can't select specific commits in dub, 
but I try to keep up with the updates and make them work 
somehow. Sometimes it feels like unnecessary major (minor) 
version bumps that just break all the version compatibility 
with barely any backwards incompatibility in the code.


thanks,fix after reloading vs code several times with internet 
connection. DCD was not downloaded i have to manually download 
it, extract it and copy dcd-client.exe and dcd-server.exe to 
code-d\bin and set up the path in vs code for auto completion to 
work


Re: Could not setup D extension on vs code

2018-11-14 Thread WebFreak001 via Digitalmars-d-learn
On Wednesday, 14 November 2018 at 20:44:26 UTC, Neia Neutuladh 
wrote:

On Wed, 14 Nov 2018 19:28:44 +, WebFreak001 wrote:
It's a real pain that you can't select specific commits in 
dub, but I try to keep up with the updates and make them work 
somehow.


Yeah, I've used submodules and path-based dependencies once or 
twice because of that. It's not the best.


that would be the best solution if you don't publish your package 
to the dub registry. If you do publish it you have all the 
problems with it not cloning your repo recursively.


Re: Could not setup D extension on vs code

2018-11-14 Thread Neia Neutuladh via Digitalmars-d-learn
On Wed, 14 Nov 2018 19:28:44 +, WebFreak001 wrote:
> It's a real pain that you can't select specific commits in dub, but I
> try to keep up with the updates and make them work somehow.

Yeah, I've used submodules and path-based dependencies once or twice 
because of that. It's not the best.


Windows Service

2018-11-14 Thread Thomas via Digitalmars-d-learn

Hi,

I want to run a D program as a Windows service. After googl'in, I 
only found a very old project on github:

https://github.com/tylerjensen/WindowsServiceInD

Unfortunately, I wasn't able to compile it successfully.
Does anybody know of newer approaches or even a template to start 
from?


Thanks in advance,
Thomas



Re: Could not setup D extension on vs code

2018-11-14 Thread WebFreak001 via Digitalmars-d-learn
On Wednesday, 14 November 2018 at 13:20:31 UTC, greatsam4sure 
wrote:

What is the solution to this:

Unresolvable dependencies to package libdparse:
  dfmt ~master depends on libdparse ~>0.10.7
  libddoc 0.4.0 depends on libdparse ~>0.9.0
Failed to install serve-d (Error code 2)



Where can i download libdparse 0.10.7

The full error file below. i am on windows 10

Installing into C:\Users\Greatsam\AppData\Roaming\code-d\bin
Removing old version
Removed old version
git clone --recursive https://github.com/Pure-D/serve-d.git 
serve-d

Cloning into 'serve-d'...

dub upgrade
Upgrading project in 
C:\Users\Greatsam\AppData\Roaming\code-d\bin\serve-d

Unresolvable dependencies to package libdparse:
  dfmt ~master depends on libdparse ~>0.10.7
  libddoc 0.4.0 depends on libdparse ~>0.9.0
Failed to install serve-d (Error code 2)


Hi,

thanks for the report, I tagged a new version of workspace-d 
which will fix this issue.


Simply reload vscode and let it rebuild to fix.

Issue was: for a long time dfmt didn't get a new tagged release 
and wasn't compatible with the dscanner and libdparse version I 
used anymore, so I changed it to use ~master instead. Since a few 
days it has been tagged and it was added to workspace-d ~master 
but serve-d still uses the latest tagged release.


So as dfmt now got updated to an even newer libdparse, the other 
components don't match that libdparse version anymore and now 
dfmt is too new for it...


It's a real pain that you can't select specific commits in dub, 
but I try to keep up with the updates and make them work somehow. 
Sometimes it feels like unnecessary major (minor) version bumps 
that just break all the version compatibility with barely any 
backwards incompatibility in the code.


Re: Function parameters UDAs

2018-11-14 Thread Adam D. Ruppe via Digitalmars-d-learn

On Wednesday, 14 November 2018 at 16:28:19 UTC, Radu wrote:
Looks like that there is no easy way to extract a function 
parameters UDA list.


Indeed, the only way I can find is kinda crazy:

---
void foo(int f, @("test") string s) {}

void main() {
static if(is(typeof(foo) Params == __parameters))
pragma(msg, __traits(getAttributes, 
Params[1..2])); // get the second param

}
---


So, the process is:

1) alias the params with the static if + is() statement (this is 
what std.traits.Parameters does internally)


2) slice the params! using params[0] will not work, but params[0 
.. 1] will.


3) get the attributes using the language function


Re: passing subclass to superclass where parameter is a delegate for the superclass

2018-11-14 Thread Alex via Digitalmars-d-learn

On Wednesday, 14 November 2018 at 16:39:52 UTC, Alex wrote:


Are you looking for this?
https://dlang.org/phobos/std_traits.html#TransitiveBaseTypeTuple

It matches however not exactly your needs:
As all objects are derived from the Object class, you will 
always get it as the common parent. So... with the trait, you 
get a list but have still to make a decision which type to use.


Maybe, something like this:

´´´
import std.traits;

template properBase(T)
{
static foreach(i, t; TransitiveBaseTypeTuple!A)
{
static if(hasMember!(t, "add_function")){}
else
{
static if(!__traits(compiles, {auto c = 
properBase.init;}))
{
alias properBase = 
TransitiveBaseTypeTuple!A[i-1];
}
}
}
}

void main(){}

class base
{
void delegate(typeof(this)) stored_dg;
this(){}
void
add_function (void delegate (typeof(this)) dlg)
{
stored_dg = dlg;
}
}

class A : base
{
alias pB = properBase!A;
this ()
{
super ();
add_function ();
}

void foo (pB a)
{
import std.experimental.logger;
log ("i got here");
}
}
´´´


Re: passing subclass to superclass where parameter is a delegate for the superclass

2018-11-14 Thread Alex via Digitalmars-d-learn

On Wednesday, 14 November 2018 at 16:06:21 UTC, Chris Bare wrote:

If I have:
class base
{
void delegate(base) stored_dg;

void
add_function (void delegate (base) dlg)
{
stored_dg = dlg;
}
}

class A : base
{
this ()
{
super ();
add_function ();
}

void foo (A a)
{
log ("i got here");
}
}

it fails because foo(A) does not match the parameter type of 
delegate(base)


If I change foo (A a) to foo (base a)

It works, but this could be awkward in a deeper class hierarchy 
where you

might not know the class name to use.

Is there a way to do this where foo's parameter type does not 
to match the

class that implements add_function?

Thanks,
Chris


Are you looking for this?
https://dlang.org/phobos/std_traits.html#TransitiveBaseTypeTuple

It matches however not exactly your needs:
As all objects are derived from the Object class, you will always 
get it as the common parent. So... with the trait, you get a list 
but have still to make a decision which type to use.


Function parameters UDAs

2018-11-14 Thread Radu via Digitalmars-d-learn
Looks like that there is no easy way to extract a function 
parameters UDA list.


The following:
```
import std.traits;

struct s { string foo; }
void foo(@s("aaa") int a, bool x);

void main()
{
alias P = Parameters!foo;
enum udas = __traits(getAttributes, P);
pragma(msg, udas);
}
```
will print `tuple(s("aaa"))`

but if you change `foo` to `void foo(int a, @s("aaa") bool x);`

you get `Error: first argument is not a symbol`

Is this a current limitation or I'm using the wrong approach?


passing subclass to superclass where parameter is a delegate for the superclass

2018-11-14 Thread Chris Bare via Digitalmars-d-learn

If I have:
class base
{
void delegate(base) stored_dg;

void
add_function (void delegate (base) dlg)
{
stored_dg = dlg;
}
}

class A : base
{
this ()
{
super ();
add_function ();
}

void foo (A a)
{
log ("i got here");
}
}

it fails because foo(A) does not match the parameter type of 
delegate(base)


If I change foo (A a) to foo (base a)

It works, but this could be awkward in a deeper class hierarchy 
where you

might not know the class name to use.

Is there a way to do this where foo's parameter type does not to 
match the

class that implements add_function?

Thanks,
Chris


Could not setup D extension on vs code

2018-11-14 Thread greatsam4sure via Digitalmars-d-learn

What is the solution to this:

Unresolvable dependencies to package libdparse:
  dfmt ~master depends on libdparse ~>0.10.7
  libddoc 0.4.0 depends on libdparse ~>0.9.0
Failed to install serve-d (Error code 2)



Where can i download libdparse 0.10.7

The full error file below. i am on windows 10

Installing into C:\Users\Greatsam\AppData\Roaming\code-d\bin
Removing old version
Removed old version
git clone --recursive https://github.com/Pure-D/serve-d.git 
serve-d

Cloning into 'serve-d'...

dub upgrade
Upgrading project in 
C:\Users\Greatsam\AppData\Roaming\code-d\bin\serve-d

Unresolvable dependencies to package libdparse:
  dfmt ~master depends on libdparse ~>0.10.7
  libddoc 0.4.0 depends on libdparse ~>0.9.0
Failed to install serve-d (Error code 2)


Re: Differences between group() and chunkBy()

2018-11-14 Thread Dennis via Digitalmars-d-learn

On Wednesday, 14 November 2018 at 12:28:38 UTC, Per Nordlöw wrote:
Is it because of `group` has a default for the predicate 
whereas `chunkBy` hasn't.


chunkBy splits the range into smaller ranges, group actually 
returns tuples of the item and the amount of occurences. Because 
in group the condition is fixed to equality, it's redundant to 
return a range of [2, 2, 2, 2, 2, 2] for example when you can 
simply return a tuple (2, 6).


The example:
group([5, 2, 2, 3, 3]) returns a range containing the tuples 
tuple(5, 1), tuple(2, 2), and tuple(3, 2).


Is a bit confusing since tuple(2, 2) looks like it could be a 
range of two 2's as well.




Differences between group() and chunkBy()

2018-11-14 Thread Per Nordlöw via Digitalmars-d-learn

Why is there at

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

an inconsistency in naming of `group` and chunkBy`?

Is it because of `group` has a default for the predicate whereas 
`chunkBy` hasn't.


Further, why aren't the two merged into a single iteration 
algorithm?


Re: Problem with opBinary

2018-11-14 Thread realhet via Digitalmars-d-learn

Thanks, this make it clear.
(This also explains the existence of opBinaryRight)


Re: Problem with opBinary

2018-11-14 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, November 14, 2018 2:54:27 AM MST realhet via Digitalmars-d-
learn wrote:
> Hi,
>
> Just a little weird thing I noticed and don't know why it is:
>
> I have a FilePath struct and I wanted to make it work with the
> "~" operator and an additional string.
>
> So I've created a global funct:
>
>FilePath opBinary(string op:"~")(FilePath p1, string p2){
>  return FilePath(p1, p2);
>}
>
> The problem is that this funct is only callable with the
> following code:
>
>auto vlcPath = programFilesPath.opBinary!"~"(`VideoLAN\VLC`);
>
> And it is not callable using the ~ operator directly. It says
> unable to call with types  FilePath and string
>
> When I rewrite the opBinary funct as a member of the FilePath
> struct, everything is working fine. The problem is only happening
> when opBinary is a global funct. (I'm using LDC Win64)
>
> Is it a bug or is there an explanation to this?

In D, all overloaded operators must be member functions.

- Jonathan M Davis





Problem with opBinary

2018-11-14 Thread realhet via Digitalmars-d-learn

Hi,

Just a little weird thing I noticed and don't know why it is:

I have a FilePath struct and I wanted to make it work with the 
"~" operator and an additional string.


So I've created a global funct:

  FilePath opBinary(string op:"~")(FilePath p1, string p2){
return FilePath(p1, p2);
  }

The problem is that this funct is only callable with the 
following code:


  auto vlcPath = programFilesPath.opBinary!"~"(`VideoLAN\VLC`);

And it is not callable using the ~ operator directly. It says 
unable to call with types  FilePath and string


When I rewrite the opBinary funct as a member of the FilePath 
struct, everything is working fine. The problem is only happening 
when opBinary is a global funct. (I'm using LDC Win64)


Is it a bug or is there an explanation to this?


Re: Is there any way for non-blocking IO with phobos?

2018-11-14 Thread Kagamin via Digitalmars-d-learn

On Tuesday, 13 November 2018 at 13:52:57 UTC, Sobaya wrote:
But I don't know how many lines are sent from the server for an 
input, so readln function blocks.


Read lines in another thread and send them to the main thread 
with std.concurrency.