Re: Speed of math function atan: comparison D and C++

2018-03-04 Thread Era Scarecrow via Digitalmars-d-learn

On Monday, 5 March 2018 at 05:40:09 UTC, rikki cattermole wrote:
atan should work out to only be a few instructions (inline 
assembly) from what I've looked at in the source.


Also you should post the code you used for each.


 Should be 3-4 instructions. Load input to the FPU (Optional? 
Depends on if it already has the value loaded), Atan, Fwait 
(optional?), Retrieve value.


 Off hand that i remember, FPU instructions run in their own 
separated space and should more or less take up only a few cycles 
by themselves to run (and also run in parallel to the CPU code).


 At which point if the code is running half the speed of C++'s, 
that means probably bad optimization elsewhere, or even the 
control settings for the FPU.


 I really haven't looked that in depth to the FPU stuff since 
about 2000...


Re: Speed of math function atan: comparison D and C++

2018-03-04 Thread rikki cattermole via Digitalmars-d-learn

On 05/03/2018 7:01 PM, J-S Caux wrote:

On Monday, 5 March 2018 at 05:40:09 UTC, rikki cattermole wrote:

On 05/03/2018 6:35 PM, J-S Caux wrote:
I'm considering shifting a large existing C++ codebase into D (it's a 
scientific code making much use of functions like atan, log etc).


I've compared the raw speed of atan between C++ (Apple LLVM version 
7.3.0 (clang-703.0.29)) and D (dmd v2.079.0, also ldc2 1.7.0) by 
doing long loops of such functions.


I can't get the D to run faster than about half the speed of C++.

Are there benchmarks for such scientific functions published somewhere


Gonna need to disassemble and compare them.

atan should work out to only be a few instructions (inline assembly) 
from what I've looked at in the source.


Also you should post the code you used for each.


So the codes are trivial, simply some check of raw speed:

   double x = 0.0;
   for (int a = 0; a < 10; ++a) x += atan(1.0/(1.0 + sqrt(1.0 + 
a)));


for C++ and

   double x = 0.0;
   for (int a = 0; a < 1_000_000_000; ++a) x += atan(1.0/(1.0 + sqrt(1.0 
+ a)));


for D. C++ exec takes 40 seconds, D exec takes 68 seconds.


Yes, but that doesn't show me how you benchmarked.


Re: Speed of math function atan: comparison D and C++

2018-03-04 Thread J-S Caux via Digitalmars-d-learn

On Monday, 5 March 2018 at 05:40:09 UTC, rikki cattermole wrote:

On 05/03/2018 6:35 PM, J-S Caux wrote:
I'm considering shifting a large existing C++ codebase into D 
(it's a scientific code making much use of functions like 
atan, log etc).


I've compared the raw speed of atan between C++ (Apple LLVM 
version 7.3.0 (clang-703.0.29)) and D (dmd v2.079.0, also ldc2 
1.7.0) by doing long loops of such functions.


I can't get the D to run faster than about half the speed of 
C++.


Are there benchmarks for such scientific functions published 
somewhere


Gonna need to disassemble and compare them.

atan should work out to only be a few instructions (inline 
assembly) from what I've looked at in the source.


Also you should post the code you used for each.


So the codes are trivial, simply some check of raw speed:

  double x = 0.0;
  for (int a = 0; a < 10; ++a) x += atan(1.0/(1.0 + 
sqrt(1.0 + a)));


for C++ and

  double x = 0.0;
  for (int a = 0; a < 1_000_000_000; ++a) x += atan(1.0/(1.0 + 
sqrt(1.0 + a)));


for D. C++ exec takes 40 seconds, D exec takes 68 seconds.


Re: Speed of math function atan: comparison D and C++

2018-03-04 Thread rikki cattermole via Digitalmars-d-learn

On 05/03/2018 6:35 PM, J-S Caux wrote:
I'm considering shifting a large existing C++ codebase into D (it's a 
scientific code making much use of functions like atan, log etc).


I've compared the raw speed of atan between C++ (Apple LLVM version 
7.3.0 (clang-703.0.29)) and D (dmd v2.079.0, also ldc2 1.7.0) by doing 
long loops of such functions.


I can't get the D to run faster than about half the speed of C++.

Are there benchmarks for such scientific functions published somewhere


Gonna need to disassemble and compare them.

atan should work out to only be a few instructions (inline assembly) 
from what I've looked at in the source.


Also you should post the code you used for each.


Speed of math function atan: comparison D and C++

2018-03-04 Thread J-S Caux via Digitalmars-d-learn
I'm considering shifting a large existing C++ codebase into D 
(it's a scientific code making much use of functions like atan, 
log etc).


I've compared the raw speed of atan between C++ (Apple LLVM 
version 7.3.0 (clang-703.0.29)) and D (dmd v2.079.0, also ldc2 
1.7.0) by doing long loops of such functions.


I can't get the D to run faster than about half the speed of C++.

Are there benchmarks for such scientific functions published 
somewhere?





Re: VibeD Rest Interface Generator

2018-03-04 Thread aberba via Digitalmars-d-learn

On Saturday, 3 March 2018 at 02:32:11 UTC, Mario wrote:
So I've been learning D since the day 11 (I posted for first 
time here) and now I've decided to try Vibe.D to make my 
company API.


The fact is that I've achieved to do it (according to the 
provided code) and it works! But it shows a default message and 
on the startup. So I'd like to know how can I set it to receive 
the HTTP(s) request, analyze the body and get the data through 
a database (we will probably use MongoDB).


If you can help me with this, I'd be grateful. Best regards, 
Mario :-)


The "examples" folder of vibe.d code on Github has demo on using 
HTTPS, mongodb query and many others. Check it out.


is it possible to put some DDOC after auto generated blocks like unittest examples?

2018-03-04 Thread arturg via Digitalmars-d-learn

///
void fun(){}

///$(TABLE $(TR $(TD Back to:) $(TD href="#fun">Declaration) $(TD $(LINK2 #top, Top

unittest
{

}

it basically should look like this:

Declaration
void fun()

Example
---

---
[Back to:] [Declaration] [Top]


and if i replace the embbeded html with $(LINK2 #fun, 
Declaration) inside the doc comment of the function it produses 
wrong html.


Re: Get function argument name?

2018-03-04 Thread Timothee Cour via Digitalmars-d-learn
`printName(alias var)()` is not a great solution, eg: doesn't work
with expressions, doesn't work with variadics, introduces template
bloat.

https://github.com/dlang/dmd/pull/7821 introduces
__traits(getCallerSource, symbol) which will allow what you want.

On Sun, Mar 4, 2018 at 1:53 PM, bauss via Digitalmars-d-learn
 wrote:
> On Sunday, 4 March 2018 at 21:48:53 UTC, JN wrote:
>>
>> On Sunday, 4 March 2018 at 21:12:44 UTC, arturg wrote:
>>>
>>>
>>> you can pass it by alias:
>>>
>>> import std.stdio;
>>>
>>> void main(string[] args)
>>> {
>>> int x;
>>> printName!(x);
>>> }
>>>
>>> void printName(alias var)()
>>> {
>>> writeln(__traits(identifier, var), " ", var);
>>> }
>>
>>
>> Well, it works. But I am confused now, why. Isn't alias only for types
>> (like a typedef)? Why can we use it for variable here?
>
>
> Because it is what it is, an alias. Not a type.
>
> It can be a type, expression or member/variable.


Re: isInputRange copied verbatim produces a different result than isInputRange from std.range

2018-03-04 Thread arturg via Digitalmars-d-learn

On Sunday, 4 March 2018 at 21:47:43 UTC, Jonathan M Davis wrote:
On Sunday, March 04, 2018 21:03:23 arturg via 
Digitalmars-d-learn wrote:


isn't this what DIP 1005 tried to solve?


No. What DIP 1005 was trying to solve was avoiding having to 
have imports used by your function signature or template 
constraint on top-level constructs be available to the entire 
module. It wanted the imports to only kick in when the symbol 
that needed them was used. So, it would be possible to then 
import isInputRange as part of a function that needed it in its 
template constraint without the rest of the module seeing that 
import, whereas right now, such an import would have to be at 
the top level and would affect the entire module. DIP 1005 
didn't do anything to make it so that other modules could see 
what you imported, and I doubt that any DIP ever would, because 
if that were possible, it would cause function hijacking, 
because you could force other modules to import what you wanted 
instead of what the person who wrote them imported.


- Jonathan M Davis


hm yeah i hoped that dip 1005 would be introspectable so you 
could use it instead of relying on udas.


Re: Get function argument name?

2018-03-04 Thread bauss via Digitalmars-d-learn

On Sunday, 4 March 2018 at 21:48:53 UTC, JN wrote:

On Sunday, 4 March 2018 at 21:12:44 UTC, arturg wrote:


you can pass it by alias:

import std.stdio;

void main(string[] args)
{
int x;
printName!(x);
}

void printName(alias var)()
{
writeln(__traits(identifier, var), " ", var);
}


Well, it works. But I am confused now, why. Isn't alias only 
for types (like a typedef)? Why can we use it for variable here?


Because it is what it is, an alias. Not a type.

It can be a type, expression or member/variable.


Re: Get function argument name?

2018-03-04 Thread JN via Digitalmars-d-learn

On Sunday, 4 March 2018 at 21:12:44 UTC, arturg wrote:


you can pass it by alias:

import std.stdio;

void main(string[] args)
{
int x;
printName!(x);
}

void printName(alias var)()
{
writeln(__traits(identifier, var), " ", var);
}


Well, it works. But I am confused now, why. Isn't alias only for 
types (like a typedef)? Why can we use it for variable here?


Re: isInputRange copied verbatim produces a different result than isInputRange from std.range

2018-03-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, March 04, 2018 21:03:23 arturg via Digitalmars-d-learn wrote:
> On Sunday, 4 March 2018 at 19:58:14 UTC, ag0aep6g wrote:
> > On 03/04/2018 08:54 PM, aliak wrote:
> >> wait a minute... so I can't use any std.range functions on a
> >> type if I add the range primitives as free functions? O.o
> >
> > Yes. In other words: You can't implement range primitives as
> > free functions. Because std.range (and std.algorithm, etc.)
> > doesn't know about them.
>
> isn't this what DIP 1005 tried to solve?

No. What DIP 1005 was trying to solve was avoiding having to have imports
used by your function signature or template constraint on top-level
constructs be available to the entire module. It wanted the imports to only
kick in when the symbol that needed them was used. So, it would be possible
to then import isInputRange as part of a function that needed it in its
template constraint without the rest of the module seeing that import,
whereas right now, such an import would have to be at the top level and
would affect the entire module. DIP 1005 didn't do anything to make it so
that other modules could see what you imported, and I doubt that any DIP
ever would, because if that were possible, it would cause function
hijacking, because you could force other modules to import what you wanted
instead of what the person who wrote them imported.

- Jonathan M Davis



Re: Template Class With Default Values

2018-03-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, March 04, 2018 14:43:41 bauss via Digitalmars-d-learn wrote:
> On Sunday, 4 March 2018 at 11:57:12 UTC, Jonathan M Davis wrote:
> > On Sunday, March 04, 2018 11:35:23 bauss via
> >
> > Digitalmars-d-learn wrote:
> >> Why is the following not working?
> >>
> >> class Foo(string baz = "baz")
> >> {
> >>
> >>  mixin("int " ~ baz ~ ";");
> >>
> >> }
> >>
> >> class Bar : Foo
> >> {
> >> }
> >>
> >> Shouldn't it implicit do, without me having to do it manually?
> >>
> >> class Bar : Foo!"baz"
> >> {
> >> }
> >>
> >> ...
> >>
> >> What's the reason you can't specify default values for
> >> template parameters on a class? Is it intended behavior or is
> >> it a bug?
> >>
> >> https://run.dlang.io/is/tnOtn3
> >
> > If it were allowed, it would be ambiguous. e.g. what would
> >
> > alias Foobar = Foo;
> >
> > mean? Would it be the default instantiation of Foo!"baz" or
> > would it be the template itself? Right now, it's always the
> > template itself, and in all cases except for functions,
> > templates must be explicitly instantiated.
> >
> > For function templates, we have IFTI (Implicit Function
> > Template Instantiation) where the compiler tries to infer the
> > template arguments based on the function arguments. It works
> > because the function call syntax is unambiguous such that if
> > you have
> >
> > auto foo(T = string)(T t) {...}
> >
> > alias foobar = foo;
> >
> > it's guaranteed that foobar is the template foo and not an
> > instantiation. It would certainly be possible to make the
> > compiler implicitly instantiate templates that aren't functions
> > under specific circumstances, but it can't be done in the
> > general case, so rather than creating a situation with subtle
> > rules about when it's necessary to explicitly instantiate a
> > template and when it's not, it's simply always required to
> > explicitly instantiate templates other than function templates.
> > And based on Walter's comment in the associated enhancement
> > request, he has concerns that allowing implicit template
> > instantiations like this would cause serious problems.
> >
> > https://issues.dlang.org/show_bug.cgi?id=1012
> >
> > Really, this is one of those things that at first seems like
> > it's crazy that it doesn't work, but as the details become
> > clearer, it starts seeming a lot less reasonable to try to make
> > it work.
> >
> > - Jonathan M Davis
>
> It wouldn't be ambiguous if it had same behavior as every other
> templates.
>
> Ex.
>
> void foo(string a = "a")() { writeln(a); }
>
> alias foo2 = foo; // Error ... The class situation should be the
> same.
>
> Which forces you to do
>
> alias foob = foo!"b";
>
> Which means that the following would work properly:
>
>  foo;
>  foo!"b";
>  foob;
>
> Which is why it doesn't seem right that classes can't work the
> same way.

Except that aliasing templates of any kind is legal. So,

alias foo2 = foo;

is legal just like

alias bar = isInputRange;

is legal. And in all cases, it aliases the template, not the instantiation,
whether there are default template arguments or not. It only aliases the
instantiation if the template is explicitly instantiated in the alias.

There's nothing special about class or struct templates here, and the only
thing special about function templates is that we have IFTI, which only
kicks in when a function template is called.

- Jonathan M Davis



Re: Get function argument name?

2018-03-04 Thread arturg via Digitalmars-d-learn

On Sunday, 4 March 2018 at 21:03:04 UTC, JN wrote:

Imagine a function like this:

void printValue(T)(string name, T value)
{
  writeln(name, " = ", value);
}

int x = 10;
printValue("x", x);

is it somehow possible to convert that printValue into a mixin 
or something, so I could do something like:


printValue(x);

and it will figure out the "x" part automatically?


you can pass it by alias:

import std.stdio;

void main(string[] args)
{
int x;
printName!(x);
}

void printName(alias var)()
{
writeln(__traits(identifier, var), " ", var);
}



Re: isInputRange copied verbatim produces a different result than isInputRange from std.range

2018-03-04 Thread arturg via Digitalmars-d-learn

On Sunday, 4 March 2018 at 19:58:14 UTC, ag0aep6g wrote:

On 03/04/2018 08:54 PM, aliak wrote:
wait a minute... so I can't use any std.range functions on a 
type if I add the range primitives as free functions? O.o


Yes. In other words: You can't implement range primitives as 
free functions. Because std.range (and std.algorithm, etc.) 
doesn't know about them.


isn't this what DIP 1005 tried to solve?

as long as you dont want to role your own test its not possible.

module moda;

struct Imports
{
string importString;
}

template isInputRange(R)
{
import std.traits: hasUDA, getUDAs, ReturnType;

static if(hasUDA!(R, Imports))
static foreach(u; getUDAs!(R, Imports))
mixin(u.importString);

enum bool isInputRange =
is(typeof(R.init) == R)
&& is(ReturnType!((R r) => r.empty) == bool)
&& is(typeof((return ref R r) => r.front))
&& !is(ReturnType!((R r) => r.front) == void)
&& is(typeof((R r) => r.popFront));
}

-

module test;

import std.stdio;
import moda;

void main(string[] args)
{
isInputRange!Type.writeln;
}

bool empty(Type t) { return true; }
int front(Type t) { return 42; }
void popFront(Type t) {}

@Imports("import test: empty, front, popFront;")
struct Type
{
}




Get function argument name?

2018-03-04 Thread JN via Digitalmars-d-learn

Imagine a function like this:

void printValue(T)(string name, T value)
{
  writeln(name, " = ", value);
}

int x = 10;
printValue("x", x);

is it somehow possible to convert that printValue into a mixin or 
something, so I could do something like:


printValue(x);

and it will figure out the "x" part automatically?


Re: importing std.array: empty in a struct messes things up

2018-03-04 Thread arturg via Digitalmars-d-learn

On Sunday, 4 March 2018 at 20:07:06 UTC, visitor wrote:

On Sunday, 4 March 2018 at 19:53:59 UTC, ag0aep6g wrote:

On 03/04/2018 08:45 PM, ag0aep6g wrote:
I don't know what's going on here. The error message doesn't 
make sense to me. Might be a bug in the compiler.


This one works:


struct Stack(T) {
T[] stack;
alias stack this;
bool empty() {return empty(stack);} /* not using UFCS */
import std.array: empty; /* has to come after the method */
}


Looks very much like a compiler bug now. As far as I know, the 
order of declarations shouldn't have an effect like that in 
structs. And UFCS should also be ok there, as far as I can 
tell.


?
https://run.dlang.io/is/Ws0qEx
https://run.dlang.io/is/Bancgx


struct Stack(T) {
import std.array: empty;
T[] stack;
alias stack this;
bool empty() { return empty(stack); }
}

void main()
{
Stack!int stack;
//bool x = stack.empty; // fails
bool x = stack.empty(); // works
}


Re: Which Multithreading Solution?

2018-03-04 Thread Adam Wilson via Digitalmars-d-learn

On 3/4/18 11:31, Drew Phil wrote:

Hey there!

I'm trying to figure out which of D's many multithreading options to use
for my application. I'm making a game that runs at 60 frames per second
that can also run user-made Lua scripts. I would like to have the Lua
scripts run in a separate thread so they can't delay frames if there's a
lot of work to do in a burst, but I also need it to be able to update
and read from the thread where everything else is.

I don't think message passing is going to cut it because the Lua thread
is going to need to be able to request to set a value in D on one line,
and then request that value back on the next line, and that value needs
to be updated at that point, not at the end. I've been marking things as
__gshared to get them working, but I think that just makes a copy on all
threads, which seems pretty excessive when mostly the Lua will just be
reading values, and occasionally calling a function in D to change some
values.

I think I should try to do some kind of lock thing, but I'm not really
sure how that works. If someone could advise me on what tact I should
take, that would be very helpful.

Thanks!


core.thread is probably your best bet in the long-term. std.concurrency 
could actually be used though, just call receive() immediately after 
send(). However, the performance of this may not be what you want. My 
recommendation would be to use std.concurrency to get the logic correct 
first, then worry about perf. And using std.concurrency will get some of 
the basic concepts (ex: immutable/shared) right that will port over the 
regular threads.


--
Adam Wilson
IRC: LightBender
import quiet.dlang.dev;


Re: importing std.array: empty in a struct messes things up

2018-03-04 Thread visitor via Digitalmars-d-learn

On Sunday, 4 March 2018 at 19:53:59 UTC, ag0aep6g wrote:

On 03/04/2018 08:45 PM, ag0aep6g wrote:
I don't know what's going on here. The error message doesn't 
make sense to me. Might be a bug in the compiler.


This one works:


struct Stack(T) {
T[] stack;
alias stack this;
bool empty() {return empty(stack);} /* not using UFCS */
import std.array: empty; /* has to come after the method */
}


Looks very much like a compiler bug now. As far as I know, the 
order of declarations shouldn't have an effect like that in 
structs. And UFCS should also be ok there, as far as I can tell.


?
https://run.dlang.io/is/Ws0qEx
https://run.dlang.io/is/Bancgx


Re: importing std.array: empty in a struct messes things up

2018-03-04 Thread arturg via Digitalmars-d-learn
I had the same issue, happens with any conflicting selective 
import.


It seems to work if you dont use selective imports, but importing 
it inside the function if possible is a better option.


Re: isInputRange copied verbatim produces a different result than isInputRange from std.range

2018-03-04 Thread ag0aep6g via Digitalmars-d-learn

On 03/04/2018 08:54 PM, aliak wrote:
wait a minute... so I can't use any std.range functions on a type if I 
add the range primitives as free functions? O.o


Yes. In other words: You can't implement range primitives as free 
functions. Because std.range (and std.algorithm, etc.) doesn't know 
about them.


Re: isInputRange copied verbatim produces a different result than isInputRange from std.range

2018-03-04 Thread aliak via Digitalmars-d-learn

On Sunday, 4 March 2018 at 13:17:30 UTC, Adam D. Ruppe wrote:

On Sunday, 4 March 2018 at 12:57:41 UTC, aliak wrote:

@property int front(D d) { return 2; }
@property bool empty(D d) { return false; }
void popFront(D d) {}


Those functions are in scope for your function, but not inside 
std.range.


in other words std.range hasn't imported your module, so it 
can't see those three functions.


wait a minute... so I can't use any std.range functions on a type 
if I add the range primitives as free functions? O.o


Re: importing std.array: empty in a struct messes things up

2018-03-04 Thread ag0aep6g via Digitalmars-d-learn

On 03/04/2018 08:45 PM, ag0aep6g wrote:
I don't know what's going on here. The error message doesn't make sense 
to me. Might be a bug in the compiler.


This one works:


struct Stack(T) {
T[] stack;
alias stack this;
bool empty() {return empty(stack);} /* not using UFCS */
import std.array: empty; /* has to come after the method */
}


Looks very much like a compiler bug now. As far as I know, the order of 
declarations shouldn't have an effect like that in structs. And UFCS 
should also be ok there, as far as I can tell.


Re: importing std.array: empty in a struct messes things up

2018-03-04 Thread ag0aep6g via Digitalmars-d-learn

On 03/04/2018 08:17 PM, Dennis wrote:

I was making a stack interface for an array:
```
struct Stack(T) {
     import std.array: empty;
     T[] stack;
     alias stack this;
}

void main()
{
     Stack!int stack;
     bool x = stack.empty;
}
```
My expectation is that you can now call `empty` on a stack instance 
since I imported it in the struct, but it gives this error:

```
Error: cannot resolve type for stack.empty(T)(auto ref scope const(T) a) 
if (is(typeof(a.length) : size_t) || isNarrowString!T)

```


`stack.empty` is an alias of `std.array.empty`. It's not a method of the 
struct. It's not a UFCS call to `std.array.empty`.


You can call it this way: `stack.empty(stack)`. You can also call it 
this way: `Stack!int.empty(stack)`. Maybe that makes it more obvious 
what's going on.



When adding this method to the struct:
```
bool empty() {return stack.empty;}
```

I get this confusing error:
```
Error: expression stack.empty is void and has no value
```


I don't know what's going on here. The error message doesn't make sense 
to me. Might be a bug in the compiler.


Which Multithreading Solution?

2018-03-04 Thread Drew Phil via Digitalmars-d-learn

Hey there!

I'm trying to figure out which of D's many multithreading options 
to use for my application. I'm making a game that runs at 60 
frames per second that can also run user-made Lua scripts. I 
would like to have the Lua scripts run in a separate thread so 
they can't delay frames if there's a lot of work to do in a 
burst, but I also need it to be able to update and read from the 
thread where everything else is.


I don't think message passing is going to cut it because the Lua 
thread is going to need to be able to request to set a value in D 
on one line, and then request that value back on the next line, 
and that value needs to be updated at that point, not at the end. 
I've been marking things as __gshared to get them working, but I 
think that just makes a copy on all threads, which seems pretty 
excessive when mostly the Lua will just be reading values, and 
occasionally calling a function in D to change some values.


I think I should try to do some kind of lock thing, but I'm not 
really sure how that works. If someone could advise me on what 
tact I should take, that would be very helpful.


Thanks!


importing std.array: empty in a struct messes things up

2018-03-04 Thread Dennis via Digitalmars-d-learn

I was making a stack interface for an array:
```
struct Stack(T) {
import std.array: empty;
T[] stack;
alias stack this;
}

void main()
{
Stack!int stack;
bool x = stack.empty;
}
```
My expectation is that you can now call `empty` on a stack 
instance since I imported it in the struct, but it gives this 
error:

```
Error: cannot resolve type for stack.empty(T)(auto ref scope 
const(T) a) if (is(typeof(a.length) : size_t) || isNarrowString!T)

```

When adding this method to the struct:
```
bool empty() {return stack.empty;}
```

I get this confusing error:
```
Error: expression stack.empty is void and has no value
```

I can solve this by importing std.array: empty in the method 
instead of the struct, but for my understanding of import 
statements in structs I'd appreciate if someone explained what 
these errors mean and why exactly they occur.


Thanks.


Re: What's the proper way to add a local file dependence to dub?

2018-03-04 Thread bauss via Digitalmars-d-learn

On Sunday, 4 March 2018 at 16:46:56 UTC, Marc wrote:

then copy it to sources folder?

let's say I have a small library folder at C:\mylibrary\D where 
I want to use dir.d from it. How do I add that file dependence 
to dub? But I do not want to that file be passed directly to 
dmd, I want to that file be copied to application's source 
folder (so it's easy to distribuite, with the dependences 
together as possible) then compiled. So, what I want to some 
extension is dub work with loca files.
Is this possible to do solely with dub? I know I can easily 
write a script to run before dub which copies the dependence 
files from C:\mylibrary to application's source but I'm looking 
for a more elegant
 approach as possible; I'm afraid of rewriting a makefile-like 
soon (I find cmake/make/makefiles just ugly).


Make it a sub package.


Any crash reporter for D?

2018-03-04 Thread Marc via Digitalmars-d-learn
Does anyone knows about any crash repórter library for D? there's 
nothing I couldn't find at code packages. Something as simple and 
easy to use like this C#'s 
https://archive.codeplex.com/?p=crashreporterdotnet


Re: howto run unittest of a single module in dub driven project?

2018-03-04 Thread Basile B. via Digitalmars-d-learn

On Sunday, 4 March 2018 at 12:22:35 UTC, Basile B. wrote:

On Sunday, 4 March 2018 at 11:38:37 UTC, Basile B. wrote:

On Sunday, 4 March 2018 at 10:43:06 UTC, Arjan wrote:

[...]


In Coedit yes.

1/ The path to the other source (usually the path>/src/ or /source/) folder must be 
registered in the library manager.
2/ Menu "Compilation" item "Run file unittests", which test 
the module that have the focus in the editor.



Relevant manual page:

- http://bbasile.github.io/Coedit/features_runnables#other 
(The action Run file unittest is almost the same thing as a 
runnable, except that -unittest is added to the switches byt 
the IDE).
- http://bbasile.github.io/Coedit/widgets_library_manager : 
dependencies for single  module to be run or executed must be 
reistered here.


And finally i can say that it works fine since i use this 
system for years.


Actually i realize that i only work well when the project is a 
library.

And this is probably a limitation i could remove in the IDE.


NVM, will be in Coedit 3.6.4[1]. This will work for applications 
sources too, assuming the main in is app.d


[1] 
https://github.com/BBasile/Coedit/commit/f8c5e686c8c6aaa7dc2c770121767e3e59806a0e


Thanks for givin me the idea original poster.


What's the proper way to add a local file dependence to dub?

2018-03-04 Thread Marc via Digitalmars-d-learn

then copy it to sources folder?

let's say I have a small library folder at C:\mylibrary\D where I 
want to use dir.d from it. How do I add that file dependence to 
dub? But I do not want to that file be passed directly to dmd, I 
want to that file be copied to application's source folder (so 
it's easy to distribuite, with the dependences together as 
possible) then compiled. So, what I want to some extension is dub 
work with loca files.
Is this possible to do solely with dub? I know I can easily write 
a script to run before dub which copies the dependence files from 
C:\mylibrary to application's source but I'm looking for a more 
elegant
 approach as possible; I'm afraid of rewriting a makefile-like 
soon (I find cmake/make/makefiles just ugly).




Re: isInputRange copied verbatim produces a different result than isInputRange from std.range

2018-03-04 Thread aliak via Digitalmars-d-learn

On Sunday, 4 March 2018 at 13:17:30 UTC, Adam D. Ruppe wrote:

On Sunday, 4 March 2018 at 12:57:41 UTC, aliak wrote:

@property int front(D d) { return 2; }
@property bool empty(D d) { return false; }
void popFront(D d) {}


Those functions are in scope for your function, but not inside 
std.range.


in other words std.range hasn't imported your module, so it 
can't see those three functions.


Ah, of course!
Thanks!


Re: Fastest way to zero a slice of memory

2018-03-04 Thread bauss via Digitalmars-d-learn

On Sunday, 4 March 2018 at 15:23:41 UTC, Nordlöw wrote:

When zeroing a slice of memory (either stack or heap) such as

enum n = 100;
ubyte[n] chunk;

should I use `memset` such as

memset(chunk.ptr, 0, n/2); // zero first half

or an array assignment such as

chunk[0 .. n/2] = 0; // zero first half

or are they equivalent in release mode?

Further, does it depend on whether the slice length is known at 
compile-time or not?


This is worth reading:

https://stackoverflow.com/questions/3654905/faster-way-to-zero-memory-than-with-memset


Fastest way to zero a slice of memory

2018-03-04 Thread Nordlöw via Digitalmars-d-learn

When zeroing a slice of memory (either stack or heap) such as

enum n = 100;
ubyte[n] chunk;

should I use `memset` such as

memset(chunk.ptr, 0, n/2); // zero first half

or an array assignment such as

chunk[0 .. n/2] = 0; // zero first half

or are they equivalent in release mode?

Further, does it depend on whether the slice length is known at 
compile-time or not?


Re: Template Class With Default Values

2018-03-04 Thread bauss via Digitalmars-d-learn

On Sunday, 4 March 2018 at 11:59:52 UTC, Mike Parker wrote:

On Sunday, 4 March 2018 at 11:35:23 UTC, bauss wrote:

Why is the following not working?

class Foo(string baz = "baz")
{
mixin("int " ~ baz ~ ";");
}

class Bar : Foo
{
}

Shouldn't it implicit do, without me having to do it manually?

class Bar : Foo!"baz"
{
}



class Bar : Foo!()
{
}


Still seems unneccessary.


Re: Template Class With Default Values

2018-03-04 Thread bauss via Digitalmars-d-learn

On Sunday, 4 March 2018 at 11:57:12 UTC, Jonathan M Davis wrote:
On Sunday, March 04, 2018 11:35:23 bauss via 
Digitalmars-d-learn wrote:

Why is the following not working?

class Foo(string baz = "baz")
{
 mixin("int " ~ baz ~ ";");
}

class Bar : Foo
{
}

Shouldn't it implicit do, without me having to do it manually?

class Bar : Foo!"baz"
{
}

...

What's the reason you can't specify default values for 
template parameters on a class? Is it intended behavior or is 
it a bug?


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


If it were allowed, it would be ambiguous. e.g. what would

alias Foobar = Foo;

mean? Would it be the default instantiation of Foo!"baz" or 
would it be the template itself? Right now, it's always the 
template itself, and in all cases except for functions, 
templates must be explicitly instantiated.


For function templates, we have IFTI (Implicit Function 
Template Instantiation) where the compiler tries to infer the 
template arguments based on the function arguments. It works 
because the function call syntax is unambiguous such that if 
you have


auto foo(T = string)(T t) {...}

alias foobar = foo;

it's guaranteed that foobar is the template foo and not an 
instantiation. It would certainly be possible to make the 
compiler implicitly instantiate templates that aren't functions 
under specific circumstances, but it can't be done in the 
general case, so rather than creating a situation with subtle 
rules about when it's necessary to explicitly instantiate a 
template and when it's not, it's simply always required to 
explicitly instantiate templates other than function templates. 
And based on Walter's comment in the associated enhancement 
request, he has concerns that allowing implicit template 
instantiations like this would cause serious problems.


https://issues.dlang.org/show_bug.cgi?id=1012

Really, this is one of those things that at first seems like 
it's crazy that it doesn't work, but as the details become 
clearer, it starts seeming a lot less reasonable to try to make 
it work.


- Jonathan M Davis


It wouldn't be ambiguous if it had same behavior as every other 
templates.


Ex.

void foo(string a = "a")() { writeln(a); }

alias foo2 = foo; // Error ... The class situation should be the 
same.


Which forces you to do

alias foob = foo!"b";

Which means that the following would work properly:

foo;
foo!"b";
foob;

Which is why it doesn't seem right that classes can't work the 
same way.





Re: isInputRange copied verbatim produces a different result than isInputRange from std.range

2018-03-04 Thread Adam D. Ruppe via Digitalmars-d-learn

On Sunday, 4 March 2018 at 12:57:41 UTC, aliak wrote:

@property int front(D d) { return 2; }
@property bool empty(D d) { return false; }
void popFront(D d) {}


Those functions are in scope for your function, but not inside 
std.range.


in other words std.range hasn't imported your module, so it can't 
see those three functions.


isInputRange copied verbatim produces a different result than isInputRange from std.range

2018-03-04 Thread aliak via Digitalmars-d-learn
Hi, I have a custom type D with front/popFront/empty implemented 
as free functions, but isInputRange returns false. I copied the 
implementation of isInputRange, and that custom implementation 
returns true... anyone know what's going on here?


===
import std.stdio, std.range, std.traits;

// Code copied veratim from:
// 
https://github.com/dlang/phobos/blob/v2.079.0/std/range/primitives.d#L164

enum bool isIR(R) =
is(typeof(R.init) == R)
&& is(ReturnType!((R r) => r.empty) == bool)
&& is(typeof((return ref R r) => r.front))
&& !is(ReturnType!((R r) => r.front) == void)
&& is(typeof((R r) => r.popFront));

struct D {}

@property int front(D d) { return 2; }
@property bool empty(D d) { return false; }
void popFront(D d) {}

pragma(msg, isIR!D); // true
pragma(msg, isInputRange!D); // false ???

pragma(msg, is(typeof(D.init) == D)); // true
pragma(msg, is(ReturnType!((D r) => r.empty) == bool)); // true
pragma(msg, is(typeof((return ref D r) => r.front))); // true
pragma(msg, !is(ReturnType!((D r) => r.front) == void)); // true
pragma(msg, is(typeof((D r) => r.popFront))); // true

void main() {}
===

Thanks for any help!
- Ali


Re: howto run unittest of a single module in dub driven project?

2018-03-04 Thread Basile B. via Digitalmars-d-learn

On Sunday, 4 March 2018 at 11:38:37 UTC, Basile B. wrote:

On Sunday, 4 March 2018 at 10:43:06 UTC, Arjan wrote:

[...]


In Coedit yes.

1/ The path to the other source (usually the path>/src/ or /source/) folder must be registered 
in the library manager.
2/ Menu "Compilation" item "Run file unittests", which test the 
module that have the focus in the editor.



Relevant manual page:

- http://bbasile.github.io/Coedit/features_runnables#other (The 
action Run file unittest is almost the same thing as a 
runnable, except that -unittest is added to the switches byt 
the IDE).
- http://bbasile.github.io/Coedit/widgets_library_manager : 
dependencies for single  module to be run or executed must be 
reistered here.


And finally i can say that it works fine since i use this 
system for years.


Actually i realize that i only work well when the project is a 
library.

And this is probably a limitation i could remove in the IDE.


Re: Template Class With Default Values

2018-03-04 Thread Mike Parker via Digitalmars-d-learn

On Sunday, 4 March 2018 at 11:35:23 UTC, bauss wrote:

Why is the following not working?

class Foo(string baz = "baz")
{
mixin("int " ~ baz ~ ";");
}

class Bar : Foo
{
}

Shouldn't it implicit do, without me having to do it manually?

class Bar : Foo!"baz"
{
}



class Bar : Foo!()
{
}


Re: Template Class With Default Values

2018-03-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, March 04, 2018 11:35:23 bauss via Digitalmars-d-learn wrote:
> Why is the following not working?
>
> class Foo(string baz = "baz")
> {
>  mixin("int " ~ baz ~ ";");
> }
>
> class Bar : Foo
> {
> }
>
> Shouldn't it implicit do, without me having to do it manually?
>
> class Bar : Foo!"baz"
> {
> }
>
> ...
>
> What's the reason you can't specify default values for template
> parameters on a class? Is it intended behavior or is it a bug?
>
> https://run.dlang.io/is/tnOtn3

If it were allowed, it would be ambiguous. e.g. what would

alias Foobar = Foo;

mean? Would it be the default instantiation of Foo!"baz" or would it be the
template itself? Right now, it's always the template itself, and in all
cases except for functions, templates must be explicitly instantiated.

For function templates, we have IFTI (Implicit Function Template
Instantiation) where the compiler tries to infer the template arguments
based on the function arguments. It works because the function call syntax
is unambiguous such that if you have

auto foo(T = string)(T t) {...}

alias foobar = foo;

it's guaranteed that foobar is the template foo and not an instantiation. It
would certainly be possible to make the compiler implicitly instantiate
templates that aren't functions under specific circumstances, but it can't
be done in the general case, so rather than creating a situation with subtle
rules about when it's necessary to explicitly instantiate a template and
when it's not, it's simply always required to explicitly instantiate
templates other than function templates. And based on Walter's comment in
the associated enhancement request, he has concerns that allowing implicit
template instantiations like this would cause serious problems.

https://issues.dlang.org/show_bug.cgi?id=1012

Really, this is one of those things that at first seems like it's crazy that
it doesn't work, but as the details become clearer, it starts seeming a lot
less reasonable to try to make it work.

- Jonathan M Davis



Re: howto run unittest of a single module in dub driven project?

2018-03-04 Thread Basile B. via Digitalmars-d-learn

On Sunday, 4 March 2018 at 10:43:06 UTC, Arjan wrote:
Is it somehow possible to only run the unittests of a single d 
file within a dub project? Of course without resorting to 
typing the complete commandline with all versions includes 
switches etc.


In Coedit yes.

1/ The path to the other source (usually the /src/ 
or /source/) folder must be registered in the 
library manager.
2/ Menu "Compilation" item "Run file unittests", which test the 
module that have the focus in the editor.



Relevant manual page:

- http://bbasile.github.io/Coedit/features_runnables#other (The 
action Run file unittest is almost the same thing as a runnable, 
except that -unittest is added to the switches byt the IDE).
- http://bbasile.github.io/Coedit/widgets_library_manager : 
dependencies for single  module to be run or executed must be 
reistered here.


And finally i can say that it works fine since i use this system 
for years.


Template Class With Default Values

2018-03-04 Thread bauss via Digitalmars-d-learn

Why is the following not working?

class Foo(string baz = "baz")
{
mixin("int " ~ baz ~ ";");
}

class Bar : Foo
{
}

Shouldn't it implicit do, without me having to do it manually?

class Bar : Foo!"baz"
{
}

...

What's the reason you can't specify default values for template 
parameters on a class? Is it intended behavior or is it a bug?


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


howto run unittest of a single module in dub driven project?

2018-03-04 Thread Arjan via Digitalmars-d-learn
Is it somehow possible to only run the unittests of a single d 
file within a dub project? Of course without resorting to typing 
the complete commandline with all versions includes switches etc.