Re: Linker error under Ubuntu

2020-05-14 Thread evilrat via Digitalmars-d-learn

On Thursday, 14 May 2020 at 16:09:16 UTC, solidstate1991 wrote:
When I try to compile my own project under Ubuntu with dub, I 
get the following linker error:


/usr/bin/ld: .dub/obj/pixelperfectengine_pixelperfecteditor.o: 
undefined reference to symbol 'inflateEnd'
//lib/x86_64-linux-gnu/libz.so.1: error adding symbols: DSO 
missing from command line

collect2: error: ld returned 1 exit status
Error: /usr/bin/gcc failed with status: 1
/usr/bin/ldc2 failed with exit code 1.

I've checked for zlib and it was already preinstalled. I tried 
to install LLD, but that didn't help.


The latest version of my project found here: 
https://github.com/ZILtoid1991/pixelperfectengine


Um, pardon the stupid question, but did you just forgot to link 
it? I can't see a mention of it anywhere in both the old json and 
dub.sdl, and I don't see subpackages either. (does it links 
implicitly by the compiler?)


Also if it's digged up somewhere, another possibility is the link 
order issue(you need to put libs in order that adds linker 
symbols for previous libs to consume, for circular dependencies 
you can specify libs multiple times). The MS linker and LLVM 
linkers(not sure about GNU gold) does some work for you so you 
don't have to reorder libs most of the time.


Style Questionss Regarding Protection Levels

2020-05-14 Thread farm via Digitalmars-d-learn
I've got two questions. The first one is whether the labels for 
protection levels (e.g. private) should be indented like the rest 
of an aggregate's members. The second one is where should one 
place private members of a module, e.g. on the bottom, top, near 
where they're used (in the case of help functions and structures).


I'm interested in what styles are more prevalent among you all.


Re: Handle FormatSpec!char in the virtual toString() method of a class.

2020-05-14 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 13, 2020 at 12:26:21PM +, realhet via Digitalmars-d-learn wrote:
> Hello,
> 
> Is there a way to the following thing in a class instead of a struct?
> 
> --
> static struct Point
> {
> int x, y;
> 
> void toString(W)(ref W writer, scope const ref FormatSpec!char f)
> if (isOutputRange!(W, char))
> {
> // std.range.primitives.put
> put(writer, "(");
> formatValue(writer, x, f);
> put(writer, ",");
> formatValue(writer, y, f);
> put(writer, ")");
> }
> }
> --
> 
> I think the problem is that the toString() in a class is virtual, and
> don't let me to have multiple overloaded methods.
> 
> Is there a way to let format() deal with classes too?
[...]

The main issue is that template functions cannot be virtual. So to make
it work for classes, you need to forward toString to a virtual function
implemented by subclasses.  Here's one way to do it:

class Base {
// virtual method implmented by subclasses
abstract void toStringImpl(scope void delegate(const(char)[]) 
sg,
scope const ref FormatSpec!char f);

void toString(W)(ref W writer, scope const ref FormatSpec!char 
f) {
// forward to virtual method
toStringImpl((s) => formattedWrite(writer, s), f);
}
}


T

-- 
If you want to solve a problem, you need to address its root cause, not just 
its symptoms. Otherwise it's like treating cancer with Tylenol...


Compiler bug ? -preview=intpromote and Integral promotion rules not being followed for unary + - ~ operators

2020-05-14 Thread wjoe via Digitalmars-d-learn
I have a container which provides access to data via a handle. 
For book keeping I calculate some bitmasks.
Previously, when the handle type as well as the constants were 
uint, everything compiled fine.
Today I added a template parameter to be able to specify the 
handle type and I ran into this problem.


I've read the following information on the matter:

https://forum.dlang.org/thread/yqfhytyhivltamujd...@forum.dlang.org
https://issues.dlang.org/show_bug.cgi?id=18380
https://dlang.org/changelog/2.078.0.html#fix16997

However I still don't see the problem with regards to unsigned 
types.
Why is it necessary to promote a ushort or ubyte to int for the 
purpose of shifting or the one's complement ?
At least the code at the bottom of the post seems to produce 
correct results.


One problem I see with the bug fix is that, AFAIK, the int type 
in C is not a fixed bit type like it is in D where it is defined 
to be 32 bit and therefore casting to int in D can't really 
reproduce the C behavior. What  am I missing ?


Back to my container.
* Using a 32 bit type, i.e. uint, everything compiles fine.

* Using a 16 or 8 bit type, i.e. ushort and ubyte, the compiler 
complains with -preview=intpromote for the pragmas and errors out 
on assignments of the same types.

i.e. e.g.

alias handle_t = ushort;
enum handle_t MASK = 0x8000;
handle_t handle = ~MASK; // the error message is basically: 
[value is promoted to int and] 32769 can't be assigned to ushort


* Using a 64 bit type, i.e. ulong, the whole thing blows up 
because the compiler pro-, or rather, demotes the ulong to int 
and int << 40 is obviously violating a constraint of 0..31 for 
32bit types.


void main()
{
import std.conv: to;
import std.stdio;
alias t = ushort;
enum t m = 0x8000;
pragma (msg, m.to!string(16));
pragma (msg, (~m).to!string(16));
pragma (msg, (cast(int)m).to!string(16));
pragma (msg, (~cast(int)m).to!string(16));
}

2.063  : Success with output:
-
8000
7FFF
8000
7FFF
-

2.064   to 2.077.1: Success with output:
-
8000
7FFF
8000
7FFF
-

2.078.1 to 2.084.1: Success with output:
-
8000
onlineapp.d(8): Deprecation: integral promotion not done for 
`~cast(ushort)32768u`, use '-transition=intpromote' switch or 
`~cast(int)(cast(ushort)32768u)`

7FFF
8000
7FFF
-

Apart from the fact that I end up with an int, which causes all 
kinds of havoc and the annoyance that i need to cast a ushort to 
ushort to be able to assign it to a ushort, it appears to me that 
all the results are correct.


Re: Error running concurrent process and storing results in array

2020-05-14 Thread data pulverizer via Digitalmars-d-learn

On Wednesday, 13 May 2020 at 15:13:50 UTC, wjoe wrote:

On Friday, 8 May 2020 at 13:43:40 UTC, data pulverizer wrote:
[...] I also chose kernel matrix calculations, you can't 
always call a library, sometimes you just need to write 
performant code.


Aren't kernel function calls suffering a context switch though ?


Why would they?


Linker error under Ubuntu

2020-05-14 Thread solidstate1991 via Digitalmars-d-learn
When I try to compile my own project under Ubuntu with dub, I get 
the following linker error:


/usr/bin/ld: .dub/obj/pixelperfectengine_pixelperfecteditor.o: 
undefined reference to symbol 'inflateEnd'
//lib/x86_64-linux-gnu/libz.so.1: error adding symbols: DSO 
missing from command line

collect2: error: ld returned 1 exit status
Error: /usr/bin/gcc failed with status: 1
/usr/bin/ldc2 failed with exit code 1.

I've checked for zlib and it was already preinstalled. I tried to 
install LLD, but that didn't help.


The latest version of my project found here: 
https://github.com/ZILtoid1991/pixelperfectengine


Re: How to include my own library in my d program with dub ?

2020-05-14 Thread JN via Digitalmars-d-learn

On Thursday, 14 May 2020 at 12:53:43 UTC, Vinod K Chandran wrote:

Hi all,
I just build a skeleton of a Gui library(win32 based) for my 
own purpose. How do i use this in my d programs with dub ? Now, 
all files are located in a folder called "GuiLib".
Side note : Why i started making a gui library instead of 
learning language ?
Answer : By this way, i can learn the language and i will have 
my own gui library. Otherwise, i would have struggle with 
learning a third party library.


I don't know if it's up-to-date, but this should work:

https://github.com/dlang/dub/wiki/Cookbook#working-with-submodules-or-packages-that-are-not-in-the-registry

I am assuming your GUI library uses dub already for building?


How to include my own library in my d program with dub ?

2020-05-14 Thread Vinod K Chandran via Digitalmars-d-learn

Hi all,
I just build a skeleton of a Gui library(win32 based) for my own 
purpose. How do i use this in my d programs with dub ? Now, all 
files are located in a folder called "GuiLib".
Side note : Why i started making a gui library instead of 
learning language ?
Answer : By this way, i can learn the language and i will have my 
own gui library. Otherwise, i would have struggle with learning a 
third party library.


Re: DScanner warns class is undocumented, how to resolve it ?

2020-05-14 Thread Vinod K Chandran via Digitalmars-d-learn

On Thursday, 14 May 2020 at 08:02:28 UTC, Dennis wrote:
On Thursday, 14 May 2020 at 06:08:17 UTC, Vinod K Chandran 
wrote:
On Thursday, 14 May 2020 at 06:05:00 UTC, Vinod K Chandran 
wrote:

Hi all,
I wrote a class and in VS Code, DScanner says that the class 
is undocumented. How can i document a class ?


Never mind, i found the answer myself. Just like in dot net, i 
added triple forward slash comment and problem solved.


If you plan to publish your code to dub, consider actually 
documenting it or marking it private/package so it won't appear 
as an undocumented symbol.


Thanks for the reply. :)


Re: DScanner warns class is undocumented, how to resolve it ?

2020-05-14 Thread Vinod K Chandran via Digitalmars-d-learn

On Thursday, 14 May 2020 at 11:25:48 UTC, Cogitri wrote:
On Thursday, 14 May 2020 at 06:08:17 UTC, Vinod K Chandran 
wrote:

[...]


Also see https://dlang.org/spec/ddoc.html for more info on DDoc.

FWIW you can also disable the warning by adding the following 
to VSCode's settings.json:


"dscanner.ignoredKeys": [
 "dscanner.style.undocumented_declaration"
]

to your settings.json. I do that since I usually find the 
warning distracting while implementing new methods, where I 
only document things once I'm happy with the implementation and 
all the warnings about missing docs usually distract me from 
more important warnings during that phase.


Thanks for VS Code settings. Will add it to my VS Code.


Re: Easy way to format int in pragma msg ?

2020-05-14 Thread wjoe via Digitalmars-d-learn

On Thursday, 14 May 2020 at 10:58:34 UTC, WebFreak001 wrote:

On Thursday, 14 May 2020 at 09:49:15 UTC, wjoe wrote:
Is there an easy way to print an int in hexadecimal, octal or 
binary representation ?


The documentation on pragma(msg, ...) and a quick web search 
didn't provide an answer.


for simple hex/binary/etc printing use

  import std.conv;
  pragma(msg, i.to!string(16));

where you can replace 16 with your target base.

You can also use format as in the previous reply if you want 
more formatting control


That's great. Thanks for the fast reply. To both of you :)


Re: DScanner warns class is undocumented, how to resolve it ?

2020-05-14 Thread Cogitri via Digitalmars-d-learn

On Thursday, 14 May 2020 at 06:08:17 UTC, Vinod K Chandran wrote:
On Thursday, 14 May 2020 at 06:05:00 UTC, Vinod K Chandran 
wrote:

Hi all,
I wrote a class and in VS Code, DScanner says that the class 
is undocumented. How can i document a class ?


Never mind, i found the answer myself. Just like in dot net, i 
added triple forward slash comment and problem solved.


Also see https://dlang.org/spec/ddoc.html for more info on DDoc.

FWIW you can also disable the warning by adding the following to 
VSCode's settings.json:


"dscanner.ignoredKeys": [
 "dscanner.style.undocumented_declaration"
]

to your settings.json. I do that since I usually find the warning 
distracting while implementing new methods, where I only document 
things once I'm happy with the implementation and all the 
warnings about missing docs usually distract me from more 
important warnings during that phase.


Re: Easy way to format int in pragma msg ?

2020-05-14 Thread WebFreak001 via Digitalmars-d-learn

On Thursday, 14 May 2020 at 09:49:15 UTC, wjoe wrote:
Is there an easy way to print an int in hexadecimal, octal or 
binary representation ?


The documentation on pragma(msg, ...) and a quick web search 
didn't provide an answer.


for simple hex/binary/etc printing use

  import std.conv;
  pragma(msg, i.to!string(16));

where you can replace 16 with your target base.

You can also use format as in the previous reply if you want more 
formatting control


Re: Easy way to format int in pragma msg ?

2020-05-14 Thread John Chapman via Digitalmars-d-learn

On Thursday, 14 May 2020 at 09:49:15 UTC, wjoe wrote:
Is there an easy way to print an int in hexadecimal, octal or 
binary representation ?


The documentation on pragma(msg, ...) and a quick web search 
didn't provide an answer.


  import std.string;
  pragma(msg, format("%x", 10));

%x = hex
%o = octal
%b = binary


Easy way to format int in pragma msg ?

2020-05-14 Thread wjoe via Digitalmars-d-learn
Is there an easy way to print an int in hexadecimal, octal or 
binary representation ?


The documentation on pragma(msg, ...) and a quick web search 
didn't provide an answer.


Re: D and Async I/O

2020-05-14 Thread Russel Winder via Digitalmars-d-learn
On Tue, 2020-05-12 at 20:05 +0200, Jacob Carlborg via Digitalmars-d-learn
wrote:
> On 2020-05-12 11:23, Russel Winder wrote:
> 
> > As far as I can tell D has no futures… 
> 
> Future and async in vibe.d [1]. Future in Mecca [2].
> 
> [1] https://vibed.org/api/vibe.core.concurrency/async
> [2] 
> https://github.com/weka-io/mecca/blob/0593a35dd1a9978855d7db349fc1172f04cf8013/src/mecca/reactor/sync/future.d#L23

D needs something at the language level on which Vibe.d and Mecca build. This
is a lesson from Rust, Kotlin, Python, etc. worth taking up. 

Unfortunately, I can't see D changing because it seems not enough people with
interest in developing the language have the resource/interest in this. :-(

-- 
Russel.
===
Dr Russel Winder  t: +44 20 7585 2200
41 Buckmaster Roadm: +44 7770 465 077
London SW11 1EN, UK   w: www.russel.org.uk



signature.asc
Description: This is a digitally signed message part


Re: D and Async I/O

2020-05-14 Thread Russel Winder via Digitalmars-d-learn
On Tue, 2020-05-12 at 09:57 +, Sebastiaan Koppe via Digitalmars-d-learn
wrote:
[…]
> 
> Yeah it is a shame, but you see it in almost every language. 
> Probably means concurrency and io isn't a fully solved problem 
> yet.

Whilst C frameworks use callbacks and trampolines, high level languages seem
to be basing things on futures – or things that are effectively isomorphic to
futures. Concurrency and parallelism will never be solved problems I suspect,
but I think there is a fairly good consensus now on what is state of the art.
D as a language is lagging, and this is sad.

[…]
> 
> I think there are a lot of lessons to be learned from all the 
> efforts in the programming community.
> 
> We should:
> 
> - get stackless coroutines
> - get structured concurrency
> - steal as many idea from the C++'s executors proposal 
> (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p0443r13.html)

I am not convinced C++ has the best "state of the art" in this respect – after
all it is just copying what JVM languages have had for ages, and Rust updated
for modern native code languages. But yes, if D doesn't get something in the
async/await style then its future (!) is non-existent. :-(

-- 
Russel.
===
Dr Russel Winder  t: +44 20 7585 2200
41 Buckmaster Roadm: +44 7770 465 077
London SW11 1EN, UK   w: www.russel.org.uk



signature.asc
Description: This is a digitally signed message part


Re: Sum string lengths

2020-05-14 Thread Andrey via Digitalmars-d-learn

Thanks everyone.


Re: DScanner warns class is undocumented, how to resolve it ?

2020-05-14 Thread Dennis via Digitalmars-d-learn

On Thursday, 14 May 2020 at 06:08:17 UTC, Vinod K Chandran wrote:
On Thursday, 14 May 2020 at 06:05:00 UTC, Vinod K Chandran 
wrote:

Hi all,
I wrote a class and in VS Code, DScanner says that the class 
is undocumented. How can i document a class ?


Never mind, i found the answer myself. Just like in dot net, i 
added triple forward slash comment and problem solved.


If you plan to publish your code to dub, consider actually 
documenting it or marking it private/package so it won't appear 
as an undocumented symbol.


Re: DScanner warns class is undocumented, how to resolve it ?

2020-05-14 Thread Vinod K Chandran via Digitalmars-d-learn

On Thursday, 14 May 2020 at 06:05:00 UTC, Vinod K Chandran wrote:

Hi all,
I wrote a class and in VS Code, DScanner says that the class is 
undocumented. How can i document a class ?


Never mind, i found the answer myself. Just like in dot net, i 
added triple forward slash comment and problem solved.


DScanner warns class is undocumented, how to resolve it ?

2020-05-14 Thread Vinod K Chandran via Digitalmars-d-learn

Hi all,
I wrote a class and in VS Code, DScanner says that the class is 
undocumented. How can i document a class ?