Re: cant run unittests

2018-12-09 Thread Andre Pany via Digitalmars-d-learn
On Saturday, 8 December 2018 at 19:25:41 UTC, Andrew Pennebaker 
wrote:

On Saturday, 16 July 2016 at 20:22:15 UTC, Seb wrote:

On Thursday, 14 July 2016 at 10:13:38 UTC, dom wrote:

On Thursday, 14 July 2016 at 00:33:50 UTC, ethgeh wrote:

On Wednesday, 13 July 2016 at 19:41:53 UTC, dom wrote:
how can i run my unittests for a dynamic library? some 
weird conflict is reported between main functions, my 
project doesnt contain any main function.


[...]


try to put this before the main of your application:

  "version(unittest){} else"

it looks like the default unittest config implies the switch 
"-main".


as i said my project doesnt contain a main() function


Are you sure? The error message states exactly this. Could you 
reduce the project to a single file and upload it somewhere 
(e. g. github).


I am getting the same error for my projects. I tried prefacing 
my main functions with the version(unittest) {} else snippet 
(which we really shouldn't have to do!!!) but anyway that 
didn't change the behavior of dub test at all.


It is a quite old thread but the issue is still relevant. In the 
first post, there is a dependency to poodinis which defines in 
the test package a void main function.


Maybe main functions in dependencies causing this issue. Which 
dependencies do you have?


Kind regards
Andre



Re: How to get a function name (string) @ compile time

2018-12-09 Thread Stanislav Blinov via Digitalmars-d-learn
On Sunday, 9 December 2018 at 03:29:27 UTC, Andrew Pennebaker 
wrote:


Er, when I try to use either foo.stringof, or 
__trait(identifier, foo), I always get that binding name, 
rather than the original function name, sad panda.


I can only print out the current variable name, but I want to 
print the name of the function declaration, no matter how 
deeply I pass that first function pointer into different calls 
:/


You're confusing function pointer with the function symbol. This 
will not give you the function name:


import std.stdio;

void wrap(F)(F f) { writeln(__traits(identifier, f)); }
int foo() { return 0; }
void main() { wrap(&foo); }

But this will:

import std.stdio;

auto wrap(alias f, Args...)(auto ref Args args) {
import std.functional : forward;
writeln("Calling ", __traits(identifier, f));
return f(forward!args);
}

int foo() { return 42; }
size_t bar(string x) { return x.length; }

void main() {
assert(wrap!foo == 42);
assert(wrap!bar("hello") == 5);
}



Re: Imports and Subfolders and Links (Oh, My!)

2018-12-09 Thread Ron Tarrant via Digitalmars-d-learn

Thanks everyone.


Calling function explicitly from mixin template results in recursive call instead

2018-12-09 Thread Dennis via Digitalmars-d-learn
I'm using Adam's workaround from 
https://issues.dlang.org/show_bug.cgi?id=19365, but now I have 
endless recursion. Reduced code:


```
mixin template operators() {
S opBinary(string op: "+")(S rhs) {
return rhs;
}

// (A)
auto opBinary(string op, T)(T rhs) if (false) {
return rhs;
}
}

struct S {
mixin operators ops;
S opBinary(string op, T)(T a) {
return ops.opBinary!op(a);
}
}

void main() {
S.init.opBinary!"+"(S.init);
}
```

Believe it or not, `ops.opBinary!op(a);` doesn't call anything 
from the mixin template ops, but it calls itself and it results 
in a stack overflow. I think this is a bug, but last time I was 
wrong, so maybe someone can explain what's going on here.


Note that after removing the opBinary at (A), it works. The idea 
behind it is that it converts the rhs to an S that opBinary!"+" 
takes. A less reduced version would be:


```
auto opBinary(string op, T)(T rhs) if (!is(T==S)) {
return this.opBinary!op(S(rhs));
}
```

Does anyone know how to get this working?


Re: ElementType of MapResult is a delegate??

2018-12-09 Thread Steven Schveighoffer via Digitalmars-d-learn

On 12/8/18 8:19 AM, John Chapman wrote:

On Saturday, 8 December 2018 at 13:02:00 UTC, Yuxuan Shui wrote:

This surprised me A LOT:

https://d.godbolt.org/z/82a_GZ

So if I call something.map!().array, I get an array of delegates? That 
makes no sense to me.


But in your example, "(a) =>" returns "{return tmp;}", which is a 
delegate. Just write "(a) => tmp", or invoke the delegate by turning it 
into a call: "{return tmp;}()".


This is exactly why (a) => {return tmp;} should not compile.

Almost everyone has made that mistake.

-Steve


Re: Working with ranges

2018-12-09 Thread Steven Schveighoffer via Digitalmars-d-learn

On 12/7/18 11:16 PM, Adam D. Ruppe wrote:

On Saturday, 8 December 2018 at 04:11:03 UTC, Murilo wrote:
What is the difference between declaring "int[3] a = [1,2,3];" and 
declaring "int[] a = [1,2,3];"? Is the first an array and the second a 
range?


They are both arrays, just the former one has a fixed size and the 
latter does not. Ranges require a way to iterate and consume elements, 
meaning they cannot be fixed size.


I always thought that leaving the square brackets empty would create 
an array of flexible size, it never occurred to me that it was 
creating something else.


That's what it is, just a flexible array also happens to be an array, 
whereas a fixed-size array is not one.


I think, you mean "a flexible array also happens to be *a range*..."

-Steve


Re: dmd -unittest works poorly with executables

2018-12-09 Thread Steven Schveighoffer via Digitalmars-d-learn

On 12/8/18 3:16 PM, Andrew Pennebaker wrote:
I think it's lame to have to use magical code like `version(unittest) {} 
else` to guard our main functions, when we run unit tests. Could D go 
ahead and do the right thing, automatically shadowing our main functions 
when the unit tests are run?


This is in process of deprecation, but I dropped the ball on making sure 
the deprecation happened in a timely manner (also I see the ddoc doesn't 
show the list very well...)


See this in the description of core.runtime.runModuleUnitTests: 
https://dlang.org/phobos/core_runtime.html#.runModuleUnitTests


"If the switch --DRT-testmode is passed to the executable, it can have 
one of 3 values:
1. "run-main": even if unit tests are run (and all pass), main is still 
run. This is currently the default.
2. "test-or-main": any unit tests present will cause the program to 
summarize the results and exit regardless of the result. This will be 
the default in 2.080.
3. "test-only", the runtime will always summarize and never run main, 
even if no tests are present."


Will do a PR to switch the default.

-Steve


Re: Working with ranges

2018-12-09 Thread Murilo via Digitalmars-d-learn
Hi guys, thank you for helping me out here, there is this 
facebook group for the D language, here we can help and teach 
each other. It is called Programming in D. Please join. 
https://www.facebook.com/groups/662119670846705/?ref=bookmarks


Re: Why pow() won't go beyond 2^31?

2018-12-09 Thread Murilo via Digitalmars-d-learn
Hi guys, thank you for helping me out here, there is this 
facebook group for the D language, here we can help and teach 
each other. It is called Programming in D. Please join. 
https://www.facebook.com/groups/662119670846705/?ref=bookmarks


Re: How do I install a library?

2018-12-09 Thread Murilo via Digitalmars-d-learn
Hi guys, thank you for helping me out here, there is this 
facebook group for the D language, here we can help and teach 
each other. It is called Programming in D. Please join. 
https://www.facebook.com/groups/662119670846705/?ref=bookmarks


Re: Which character set does D use?

2018-12-09 Thread Murilo via Digitalmars-d-learn
Hi guys, thank you for helping me out here, there is this 
facebook group for the D language, here we can help and teach 
each other. It is called Programming in D. Please join. 
https://www.facebook.com/groups/662119670846705/?ref=bookmarks


Re: How to get a function name (string) @ compile time

2018-12-09 Thread Arun Chandrasekaran via Digitalmars-d-learn
On Sunday, 9 December 2018 at 03:29:27 UTC, Andrew Pennebaker 
wrote:
On Monday, 3 November 2008 at 12:29:16 UTC, Simen Kjaeraas 
wrote:
On Mon, 03 Nov 2008 12:33:05 +0100, Denis Koroskin 
<2kor...@gmail.com> wrote:



[...]


That's not the only error here. Your template function also 
calls
foo with no arguments on  the line below that bug. Fixing that 
would
probably include the ParameterTypeTuple and ReturnType 
templates.


Er, when I try to use either foo.stringof, or 
__trait(identifier, foo), I always get that binding name, 
rather than the original function name, sad panda.


I can only print out the current variable name, but I want to 
print the name of the function declaration, no matter how 
deeply I pass that first function pointer into different calls 
:/


You may want to look at 
https://forum.dlang.org/post/yxobqahkvfcpcvidq...@forum.dlang.org


How may I tell dub where to find a C library for linking?

2018-12-09 Thread Pablo De Nápoli via Digitalmars-d-learn

Hi,

I was playing with the example in

https://github.com/MoritzMaxeiner/llvm-d/tree/master/examples/fibonacci

When I try to build it using dub, the linker cannot find the LLVM 
library


$ dub build
Performing "debug" build using /usr/bin/dmd for x86_64.
llvm-d 2.4.1: target for configuration "native-target" is up to 
date.

fibonacci ~master: building configuration "link-single"...
Linking...
/usr/bin/ld: cannot find -lLLVM
collect2: error: ld returned 1 exit status
Error: linker exited with status 1
/usr/bin/dmd failed with exit code 1.

On my system (Debian GNU/Linux 9, 64 bits) the library is in the 
directory /usr/lib/llvm-6.0/lib/


$ ls -l /usr/lib/llvm-6.0/lib/libLLVM.so
lrwxrwxrwx 1 root root 14 oct 24 19:44 
/usr/lib/llvm-6.0/lib/libLLVM.so -> libLLVM-6.0.so


But how am I supposed to tell dub this, so it passes this 
information to the linker??


I guess I should set "libs" in dubs.json

Off course I have tried to read the dub documentation (like 
https://code.dlang.org/package-format?lang=json) but it was not 
clear enough to me. Please note that this library cannot be find 
by pkgconfig.


Many thanks!
Pablo


Re: How may I tell dub where to find a C library for linking?

2018-12-09 Thread evilrat via Digitalmars-d-learn
On Monday, 10 December 2018 at 02:59:21 UTC, Pablo De Nápoli 
wrote:


On my system (Debian GNU/Linux 9, 64 bits) the library is in 
the directory /usr/lib/llvm-6.0/lib/


$ ls -l /usr/lib/llvm-6.0/lib/libLLVM.so
lrwxrwxrwx 1 root root 14 oct 24 19:44 
/usr/lib/llvm-6.0/lib/libLLVM.so -> libLLVM-6.0.so


But how am I supposed to tell dub this, so it passes this 
information to the linker??


I guess I should set "libs" in dubs.json



IIRC your guess is correct. "libs" is passed directly to linker 
and is the only way to do it, so you just do smth like this


   "libs" : ["-L/usr/lib/llvm-6.0/lib/", "libLLVM-6.0"]

note that this -L will be extended for linker as -L-L...
(also note that you can do platform specific way with 
"libs-windows", "libs-posix"? to pick proper paths per platform)


Though I'm not a linux pro and don't remember if linking to .so 
is same as linking import library, if this is not the case you 
just need to set RPATH or whatever it is so it can find dynamic 
lib.