Re: How to get rid of "nothrow" ?

2020-05-18 Thread drug via Digitalmars-d-learn

On 5/18/20 11:47 PM, Vinod K Chandran wrote:

On Sunday, 17 May 2020 at 19:37:05 UTC, drug wrote:

17.05.2020 17:35, Vinod K Chandran пишет:


It worked. Thanks :) I have one more question. Which is better, to 
include all the switch cases inside a single try catch or write 
separate try catch for each switch cases ?


all the switch cases inside a single try catch is better


Thanks a lot. :)


Frankly speaking in some cases separate try catch blocks will be more 
suitable but while you do not see the difference in your case then use 
the single block for everything


Re: link error on Windows

2020-05-18 Thread Joel via Digitalmars-d-learn
I tried with DMD32 D Compiler v2.088.1-dirty, and it compiled and 
created an exe file, but not run (msvcr100.dll not found - and 
tried to find it on the net without success).


Re: Is it possible to implement operators as ordinary functions?

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

On Tuesday, 19 May 2020 at 02:42:22 UTC, Adam D. Ruppe wrote:

On Tuesday, 19 May 2020 at 02:36:24 UTC, data pulverizer wrote:
I was wandering if it possible to implement operators as 
ordinary functions instead of as member functions of a class 
or struct for example something like this:


nope, it must be done as member functions.


Thanks!


Re: Is it possible to implement operators as ordinary functions?

2020-05-18 Thread Adam D. Ruppe via Digitalmars-d-learn

On Tuesday, 19 May 2020 at 02:36:24 UTC, data pulverizer wrote:
I was wandering if it possible to implement operators as 
ordinary functions instead of as member functions of a class or 
struct for example something like this:


nope, it must be done as member functions.


Is it possible to implement operators as ordinary functions?

2020-05-18 Thread data pulverizer via Digitalmars-d-learn
I was wandering if it possible to implement operators as ordinary 
functions instead of as member functions of a class or struct for 
example something like this:


```
import std.stdio: writeln;

struct Int{
  int data = 0;
}

Int opBinary(string op)(Int x1, Int x2)
{
  static if((op == "+") || (op == "-") || (op == "*") || (op == 
"/"))

  {
int ret;
mixin("ret = x1.data " ~ op ~ " x2.data");
return ret;
  }else{
static assert(0, "Operator unknown.");
  }
}

void main()
{
  Int x = Int(1);
  Int y = Int(2);
  writeln("Output: ", x + y);
}

```


Re: None of the overloads of kill are callable using argument types:

2020-05-18 Thread Ali Çehreli via Digitalmars-d-learn
On 5/18/20 1:11 PM, BoQsc wrote:> I'm trying to kill my own process, but 
I'm being unsuccessful at the

> compilation of the program. It seems that neither getpid nor
> thisProcessID returns a correct type value for the kill function.

Of course, Adam D. Ruppe is right: You can simply return from main() in 
this case. Or, Pid is given to you for processes that you've spawned.


Your question brings one of my recent pet peeves in software: the 
'private' keyword.[1] In this case, it's Pid's constructor. I wanted to 
do the following but it failed because the constructor is private:


  auto p = new Pid(thisProcessID());

Ali

[1] I don't think 'private' keyword ever protected me. I'm pretty sure 
of it because if I've ever reached for undocumented features of a type 
or if I've ever used any member, say, having a name starting with '_', I 
would be sure to be punished in the future if the implementation 
changed. I know that and I'm sure it's very easy to teach it to 
beginners. It's too much protecting me from myself.


On the other hand, there have been multiple cases where 'private' 
keyword was hiding a useful feature: D runtime's GC statistics (at least 
in the past), some of std.getopt's parsing functions, etc. Note to self: 
Think twice before making anything 'private'.




Re: any chance to get it working on windows xp?

2020-05-18 Thread rikki cattermole via Digitalmars-d-learn

On 19/05/2020 12:51 AM, a beginner wrote:

@rikki cattermole

Dmd and ldc's codegen haven't stood still for 10 years. They both will be
emitting instructions your cpu cannot handle. Hence crashes.
So... was I wrong to assume it generates code for the cpu it's running 
on (a P4 Northwood in my case) by default? I will try the "-mpcu" 
command line option then, and see if it takes care of that crash.


Yes.

Compilers make assumptions, especially dmd which uses newer instructions 
than an XP era build of dmd did.


But because D is self hosted, this means that the compiler itself has 
now been compiled with such instructions in use. So it too can crash.


Unless you bootstrap compile ldc up to the latest version (which also 
means LLVM), what options you pass it may very well not matter.


Re: After compiling Hello World with DMD Compiler, .EXE file takes 1-3 seconds to run for the first time

2020-05-18 Thread Adam D. Ruppe via Digitalmars-d-learn

On Monday, 18 May 2020 at 16:01:14 UTC, kinke wrote:
Is that really the case for all D programs on Windows, or just 
those built with -m32 and thus using the exotic DigitalMars C 
runtime?


-m32mscoff does it too, and -m64 has a slight delay as well 
(though possible that's just a cold disk cache). I don't think it 
is the runtime per se, I think it is the codegen.


It doesn't do it on ldc on my box, but possible I whitelisted 
that whole subtree so someone else should check as well.


Re: How to get rid of "nothrow" ?

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

On Sunday, 17 May 2020 at 19:37:05 UTC, drug wrote:

17.05.2020 17:35, Vinod K Chandran пишет:


It worked. Thanks :) I have one more question. Which is 
better, to include all the switch cases inside a single try 
catch or write separate try catch for each switch cases ?


all the switch cases inside a single try catch is better


Thanks a lot. :)


Re: None of the overloads of kill are callable using argument types:

2020-05-18 Thread Adam D. Ruppe via Digitalmars-d-learn

On Monday, 18 May 2020 at 20:11:25 UTC, BoQsc wrote:

I'm trying to kill my own process


Don't kill yourself, just `return` from main.


None of the overloads of kill are callable using argument types:

2020-05-18 Thread BoQsc via Digitalmars-d-learn
I'm trying to kill my own process, but I'm being unsuccessful at 
the compilation of the program. It seems that neither getpid nor 
thisProcessID returns a correct type value for the kill function.


HelloWorld.d(24): Error: none of the overloads of kill are 
callable using argument types (int), candidates are:
C:\D\dmd2\windows\bin\..\..\src\phobos\std\process.d(2327):   
 std.process.kill(Pid pid)
C:\D\dmd2\windows\bin\..\..\src\phobos\std\process.d(2338):   
 std.process.kill(Pid pid, int codeOrSignal)



HelloWorld.d


import std.stdio   : write, writeln, readln, writefln;
import std.process : executeShell, kill, thisProcessID;
import core.thread.osthread : getpid;

void main() {
executeShell("title HelloWorld");
executeShell("chcp 65001");
writeln("Hello, World!");
writeln("
 ▄ . .▄▄▌  ▄▄▌▄▄▌ ▐ ▄▌  ▄▄▄  ▄▄▌  ·
██▪▐█▀▄.▀·██•  ██•  ▪ ██· █▌▐█▪ ▀▄ █·██•  ██▪ ██
██▀▐█▐▀▀▪▄██▪  ██▪   ▄█▀▄ ██▪▐█▐▐▌ ▄█▀▄ ▐▀▀▄ ██▪  ▐█· ▐█▌
██▌▐▀▐█▄▄▌▐█▌▐▌▐█▌▐▌▐█▌.▐▌▐█▌██▐█▌▐█▌.▐▌▐█•█▌▐█▌▐▌██. ██
▀▀▀ · ▀▀▀ .▀▀▀ .▀▀▀  ▀█▄▀▪  ▀▪ ▀█▄▀▪.▀  ▀.▀▀▀ ▀•

");
writefln("Current process id: %s", getpid());
writeln("This process id: ", thisProcessID());

string line;
write("Your Input: ");
while ((line = readln()) !is null) {
writeln(line);
kill(thisProcessID());
write("Your Input: ");

}
}


Re: Spawn a Command Line application Window and output log information

2020-05-18 Thread BoQsc via Digitalmars-d-learn

On Monday, 18 May 2020 at 18:10:06 UTC, BoQsc wrote:
Also, if you want some kind of Fancy ASCII art in your 
application


Since I started this thread, I might share some more improvements.

In this Update I managed to get the PID of the current process and
in the future I hope the HelloWorld program process could be 
killed,

I'm kind of stuck right now on how.

Right now a complete Command Line command to compile HelloWorld 
example with a working Command Line Interface looks like this:

dmd HelloWorld.d whatever.res && start "" "HelloWorld.exe"



whatever.res - look at above posts on how to generate whatever.res

HelloWorld.d

import std.stdio   : write, writeln, readln, writefln;
import std.process : executeShell, kill, thisProcessID;
import core.thread.osthread : getpid;

void main() {
executeShell("title HelloWorld");
executeShell("chcp 65001");
writeln("Hello, World!");
writeln("
 ▄ . .▄▄▌  ▄▄▌▄▄▌ ▐ ▄▌  ▄▄▄  ▄▄▌  ·
██▪▐█▀▄.▀·██•  ██•  ▪ ██· █▌▐█▪ ▀▄ █·██•  ██▪ ██
██▀▐█▐▀▀▪▄██▪  ██▪   ▄█▀▄ ██▪▐█▐▐▌ ▄█▀▄ ▐▀▀▄ ██▪  ▐█· ▐█▌
██▌▐▀▐█▄▄▌▐█▌▐▌▐█▌▐▌▐█▌.▐▌▐█▌██▐█▌▐█▌.▐▌▐█•█▌▐█▌▐▌██. ██
▀▀▀ · ▀▀▀ .▀▀▀ .▀▀▀  ▀█▄▀▪  ▀▪ ▀█▄▀▪.▀  ▀.▀▀▀ ▀•

");
writefln("Current process id: %s", getpid());
writeln("This process id: ", thisProcessID());

string line;
write("Your Input: ");
while ((line = readln()) !is null) {
writeln(line);
write("Your Input: ");

}
}


Re: Spawn a Command Line application Window and output log information

2020-05-18 Thread BoQsc via Digitalmars-d-learn

On Monday, 18 May 2020 at 17:51:54 UTC, BoQsc wrote:

On Monday, 18 May 2020 at 17:20:17 UTC, BoQsc wrote:
It would be great if we could change/customise the icon of the 
Command line application that run the HelloWorld application. 
But I have a bad feeling that it is probably not possible 
without a GUI library.


Forever thankful to Adam D. Ruppe
It is possible to embed icon into the Windows executable.
The Original Adam's thread: 
https://forum.dlang.org/post/enrmidvsfdugqmudo...@forum.dlang.org


The instructions:
Download a valid Windows 3.0 icon resource
Examples: 
http://files.alexmeub.com.s3.amazonaws.com/other/win98_icons.zip


Download the tools to embed the Icon for the .exe executable.
http://ftp.digitalmars.com/bup.zip

Create a new text file named whatever.rc with the content 
similar to this:



IDI_ICON1   ICONDISCARDABLE "iconfil.ico"


Use rcc.exe tool and whatever.rc file to generate whatever.res 
file.

rcc.exe whatever.rc


Use dmd.exe compiler to embed newly created whatever.res file 
into your .exe file while compiling:

dmd.exe whatever.res


You should see that the newly compiled .exe file is now with an 
Icon.

And when launched the icon will be used by the Command Prompt.


Also, if you want some kind of Fancy ASCII art in your 
application:


Look at the Google for any ASCII Art generator:  
http://patorjk.com/software/taag/#p=display=Elite=Hello%20World


Add this line and insert your ASCII art in a writeln function.

executeShell("chcp 65001");

to your D language program source code

More about chcp can be found here: https://ss64.com/nt/chcp.html
Or here: 
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/chcp



import std.stdio   : write, writeln, readln;
import std.process : executeShell;
void main() {
executeShell("title HelloWorld");
executeShell("chcp 65001");
writeln("Hello, World!");
writeln("
 ▄ . .▄▄▌  ▄▄▌▄▄▌ ▐ ▄▌  ▄▄▄  ▄▄▌  ·
██▪▐█▀▄.▀·██•  ██•  ▪ ██· █▌▐█▪ ▀▄ █·██•  ██▪ ██
██▀▐█▐▀▀▪▄██▪  ██▪   ▄█▀▄ ██▪▐█▐▐▌ ▄█▀▄ ▐▀▀▄ ██▪  ▐█· ▐█▌
██▌▐▀▐█▄▄▌▐█▌▐▌▐█▌▐▌▐█▌.▐▌▐█▌██▐█▌▐█▌.▐▌▐█•█▌▐█▌▐▌██. ██
▀▀▀ · ▀▀▀ .▀▀▀ .▀▀▀  ▀█▄▀▪  ▀▪ ▀█▄▀▪.▀  ▀.▀▀▀ ▀•

");


string line;
while ((line = readln()) !is null)
write(line);
}


Re: Spawn a Command Line application Window and output log information

2020-05-18 Thread Kagamin via Digitalmars-d-learn

On Monday, 18 May 2020 at 17:20:17 UTC, BoQsc wrote:
It would be great if we could change/customise the icon of the 
Command line application that run the HelloWorld application. 
But I have a bad feeling that it is probably not possible 
without a GUI library.


I think the window icon is just the first icon pulled from the 
executable file.


Re: Spawn a Command Line application Window and output log information

2020-05-18 Thread BoQsc via Digitalmars-d-learn

On Monday, 18 May 2020 at 17:20:17 UTC, BoQsc wrote:
It would be great if we could change/customise the icon of the 
Command line application that run the HelloWorld application. 
But I have a bad feeling that it is probably not possible 
without a GUI library.


Forever thankful to Adam D. Ruppe
It is possible to embed icon into the Windows executable.
The Original Adam's thread: 
https://forum.dlang.org/post/enrmidvsfdugqmudo...@forum.dlang.org


The instructions:
Download a valid Windows 3.0 icon resource
Examples: 
http://files.alexmeub.com.s3.amazonaws.com/other/win98_icons.zip


Download the tools to embed the Icon for the .exe executable.
http://ftp.digitalmars.com/bup.zip

Create a new text file named whatever.rc with the content similar 
to this:



IDI_ICON1   ICONDISCARDABLE "iconfil.ico"


Use rcc.exe tool and whatever.rc file to generate whatever.res 
file.

rcc.exe whatever.rc


Use dmd.exe compiler to embed newly created whatever.res file 
into your .exe file while compiling:

dmd.exe whatever.res


You should see that the newly compiled .exe file is now with an 
Icon.

And when launched the icon will be used by the Command Prompt.






Re: Spawn a Command Line application Window and output log information

2020-05-18 Thread Adam D. Ruppe via Digitalmars-d-learn

On Monday, 18 May 2020 at 16:36:11 UTC, BoQsc wrote:

Would this require GUI library and how can this be achieved?


you might enjoy using my terminal lib

https://code.dlang.org/packages/arsd-official%3Aterminal

include that and set

"subConfigurations": {
   "arsd-official:terminal": "builtin_emulator"
}


and it gives you a gui window that acts like a terminal.

then in your program, here's a complete program you can run with

dub run --single file.d


/+ dub.sdl:
name "cool"
dependency "arsd-official:terminal" version=">=7.2.0"
subConfiguration "arsd-official:terminal" 
"builtin_emulator"

+/

import arsd.terminal;
void main() {
   auto terminal = Terminal(ConsoleOutputType.linear);
   terminal.setTitle("whatever");

   // this is possible too but you MUST have an indexed png which 
might be hard to make if you aren't ready for it.

   terminal.changeWindowIcon("your_icon.png");

   terminal.writeln("hi");

   auto got = terminal.getline("say something: ");

   terminal.writeln("you said ", got);
}


Re: Spawn a Command Line application Window and output log information

2020-05-18 Thread BoQsc via Digitalmars-d-learn

On Monday, 18 May 2020 at 17:08:41 UTC, Kagamin wrote:

On Monday, 18 May 2020 at 17:02:02 UTC, BoQsc wrote:
The important question is: how can we change the name/title of 
this Command Line application.


As the simplest solution, you can set the window title in 
shortcut properties.


It seems that all the Command Prompt Batch command of windows 
such as "title" do work well.
By using executeShell I was able to change the title of the 
Command Line that runs my program.


import std.stdio   : write, writeln, readln;
import std.process : executeShell;
void main() {
writeln("Hello, World!");
executeShell("title HelloWorld");
string line;
while ((line = readln()) !is null)
write(line);
}


import std.file : mkdir;

It would be great if we could change/customise the icon of the 
Command line application that run the HelloWorld application. But 
I have a bad feeling that it is probably not possible without a 
GUI library.


Re: Spawn a Command Line application Window and output log information

2020-05-18 Thread Kagamin via Digitalmars-d-learn

On Monday, 18 May 2020 at 17:02:02 UTC, BoQsc wrote:
The important question is: how can we change the name/title of 
this Command Line application.


As the simplest solution, you can set the window title in 
shortcut properties.


Re: Spawn a Command Line application Window and output log information

2020-05-18 Thread BoQsc via Digitalmars-d-learn

On Monday, 18 May 2020 at 16:40:24 UTC, Panke wrote:

On Monday, 18 May 2020 at 16:36:11 UTC, BoQsc wrote:
I'd like to have application as small as possible with a 
simple Command Line Window.
I'd use that Window to output notices, log information and the 
like.


Would this require GUI library and how can this be achieved?


If you do not want to create the library yourself, you could 
spawn a terminal application like konsole or kitty and start a 
simple cli app.


You'd need to have some form of inter process communication 
setup for this though.


On Windows 10, this example, when compiled and clicked on the 
executable - spawns a command line with the "Hello World" output 
shown.



import std.stdio;

void main() {
write("Hello, World!");

string line;
while ((line = readln()) !is null)
write(line);
}


The important question is: how can we change the name/title of 
this Command Line application.


Re: Spawn a Command Line application Window and output log information

2020-05-18 Thread Panke via Digitalmars-d-learn

On Monday, 18 May 2020 at 16:36:11 UTC, BoQsc wrote:
I'd like to have application as small as possible with a simple 
Command Line Window.
I'd use that Window to output notices, log information and the 
like.


Would this require GUI library and how can this be achieved?


If you do not want to create the library yourself, you could 
spawn a terminal application like konsole or kitty and start a 
simple cli app.


You'd need to have some form of inter process communication setup 
for this though.


Spawn a Command Line application Window and output log information

2020-05-18 Thread BoQsc via Digitalmars-d-learn
I'd like to have application as small as possible with a simple 
Command Line Window.
I'd use that Window to output notices, log information and the 
like.


Would this require GUI library and how can this be achieved?




Re: After compiling Hello World with DMD Compiler, .EXE file takes 1-3 seconds to run for the first time

2020-05-18 Thread kinke via Digitalmars-d-learn

On Monday, 18 May 2020 at 15:49:06 UTC, Adam D. Ruppe wrote:
It sees D programs as unusual and gives them additional 
scrutiny...


Is that really the case for all D programs on Windows, or just 
those built with -m32 and thus using the exotic DigitalMars C 
runtime?


Re: After compiling Hello World with DMD Compiler, .EXE file takes 1-3 seconds to run for the first time

2020-05-18 Thread BoQsc via Digitalmars-d-learn

On Monday, 18 May 2020 at 15:49:06 UTC, Adam D. Ruppe wrote:

On Monday, 18 May 2020 at 15:47:40 UTC, BoQsc wrote:
It seems strange that on the first run after D language 
compilation. Hello World program takes 1-3 seconds to launch.


That's the Windows virus scanner again.

It sees D programs as unusual and gives them additional 
scrutiny...


You can set an exception in the windows virus scanner settings 
for the folder where you work with D.


That's exactly what it was. I disabled the Windows Security 
Real-Time Protection,

and tested few more times. The execution was immediate.

Thanks Adam.


Re: After compiling Hello World with DMD Compiler, .EXE file takes 1-3 seconds to run for the first time

2020-05-18 Thread Adam D. Ruppe via Digitalmars-d-learn

On Monday, 18 May 2020 at 15:47:40 UTC, BoQsc wrote:
It seems strange that on the first run after D language 
compilation. Hello World program takes 1-3 seconds to launch.


That's the Windows virus scanner again.

It sees D programs as unusual and gives them additional 
scrutiny...


You can set an exception in the windows virus scanner settings 
for the folder where you work with D.


After compiling Hello World with DMD Compiler, .EXE file takes 1-3 seconds to run for the first time

2020-05-18 Thread BoQsc via Digitalmars-d-learn

I use Windows 10.
I tried exactly like mentioned here:
http://ddili.org/ders/d.en/hello_world.html

It seems strange that on the first run after D language 
compilation. Hello World program takes 1-3 seconds to launch.


While C Hello World program simply executes in a second or less.

Why is that, and what can we do about it.


Re: Compare string with German umlauts

2020-05-18 Thread Steven Schveighoffer via Digitalmars-d-learn

On 5/18/20 9:44 AM, Martin Tschierschke wrote:

Hi,
I have to find a certain line in a file, with a text containing umlauts.

How do you do this?

The following was not working:

foreach(i,line; file){
  if(line=="My text with ö oe, ä ae or ü"){
    writeln("found it at line",i)
  }
}

I ended up using line.canFind("with part of the text without umlaut").

It solved the problem, but what is the right way to use umlauts (encode 
them) inside the program?




using == on strings is going to compare the exact bits for equality. In 
unicode, things can be encoded differently to make the same grapheme. 
For example, ö is a code unit that is the o with a diaeresis (U+00F6). 
But you could encode it with 2 code points -- a standard o, and then an 
diaeresis combining character (U+006F, U+0308)


What you need is to normalize the data for comparison: 
https://dlang.org/phobos/std_uni.html#normalize


For more reference: https://en.wikipedia.org/wiki/Combining_character

-Steve


Re: Compare string with German umlauts

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

On Monday, 18 May 2020 at 13:44:15 UTC, Martin Tschierschke wrote:

Hi,
I have to find a certain line in a file, with a text containing 
umlauts.


How do you do this?

The following was not working:

foreach(i,line; file){
 if(line=="My text with ö oe, ä ae or ü"){
   writeln("found it at line",i)
 }
}

I ended up using line.canFind("with part of the text without 
umlaut").


It solved the problem, but what is the right way to use umlauts 
(encode them) inside the program?


Your code should have already worked like that, assuming your 
input file is a UTF-8 file. Check with an editor like Notepad++ 
or Visual Studio Code what the actual encoding of your text file 
is. In D all strings you specify in source are UTF-8 bytes in the 
end and a byte-by-byte comparison like with your line == "..." 
will cause it to fail if line is not UTF-8.


My guess is that your file is most likely gonna be encoded in 
Windows-1251 or Windows-1252. To quickly check if it is UTF-8, 
print out your strings but with separators between each character 
like using `writefln("%(%s, %)", line.byUTF!dchar);` and see if 
it is actually 'M', 'y', ' ', 't', 'e', 'x', 't', ' ', 'w', 'i', 
't', 'h', ' ', 'ö', ' ', 'o', 'e', ',', ' ', 'ä', ' ', 'a', 'e', 
' ', 'o', 'r', ' ', 'ü'


If you have identified that the character encoding is indeed your 
problem, interpret your line with the correct character encoding 
using


import std.encoding;
Windows1252String win1252Line = cast(Windows1252String)line;

and then convert that to utf8:

string utf8Line;
transcode(win1252Line, utf8Line);

and then compare that with your input string:

if (line == "My text with ö oe, ä ae or ü") { ... }



Alternatively you can also change your comparison string to be in 
Windows 1251/1252 encoding if you know that all your files will 
have this encoding, but I would advise against that and instead 
somehow figure out the encoding based on common German characters 
or an external library/program and always convert to UTF-8 for 
all text operations.


Another tip: if you perform case-insensitive comparision with 
UTF-8, use std.uni : sicmp or icmp (sicmp is faster / less 
advanced) and use like `sicmp(strA, strB) == 0` where you replace 
== with < or > if you want to sort. Note that this is not bound 
to any locale and is rather the invariant locale. You will 
probably want to use OS APIs or third party libraries to do 
locale based text operations (like text in UI)


Compare string with German umlauts

2020-05-18 Thread Martin Tschierschke via Digitalmars-d-learn

Hi,
I have to find a certain line in a file, with a text containing 
umlauts.


How do you do this?

The following was not working:

foreach(i,line; file){
 if(line=="My text with ö oe, ä ae or ü"){
   writeln("found it at line",i)
 }
}

I ended up using line.canFind("with part of the text without 
umlaut").


It solved the problem, but what is the right way to use umlauts 
(encode them) inside the program?




Re: any chance to get it working on windows xp?

2020-05-18 Thread a beginner via Digitalmars-d-learn

Thanks to all of you for support.

On Sunday, 17 May 2020 at 22:37:14 UTC, Seb wrote:
Alternatively, if you have a working compiler building dub from 
scratch isn't hard. You just need to clone the repo and run the 
build script (build.bat in your case).


Good luck!
I recompiled latest dub 1.21 from github (which means I was very 
likely wrong to call it 1.24), went smooth. Though, it still 
gives "access violation" when asking it to add a dependency. 
However, I noticed it seems to happily pull down dependencies if 
they're in the "dub.selections.json" file, so it's kinda usable 
after all, and what's more, I can try to debug the problem. 
Anyway I suspect the binary download would have behaved the same 
if I only though about trying before.


@rikki cattermole
Dmd and ldc's codegen haven't stood still for 10 years. They 
both will be

emitting instructions your cpu cannot handle. Hence crashes.
So... was I wrong to assume it generates code for the cpu it's 
running on (a P4 Northwood in my case) by default? I will try the 
"-mpcu" command line option then, and see if it takes care of 
that crash.


@Jonathan M Davis
I'm pretty sure that Phobos (and possibly druntime) use Windows 
API calls that
do not exist on XP and have done so for years now. You might 
get lucky and get

some stuff to work on XP, but not everything will work.
Very likely indeed. I hope I'll somehow be able to work around 
this issue, at least in some cases.


Re: D and Async I/O

2020-05-18 Thread Sebastiaan Koppe via Digitalmars-d-learn

On Thursday, 14 May 2020 at 09:36:33 UTC, Russel Winder wrote:
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.


What I find most lacking is proper cancellation. Also, futures 
are eager.


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.


I haven't found a language that ticks all the boxes. Kotlin comes 
close.


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.


I am not sure you have read the proposal. Initially I brushed it 
off, but upon closer inspection I realised there are some gems in 
there.


Re: any chance to get it working on windows xp?

2020-05-18 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, May 17, 2020 11:36:01 PM MDT Mike Parker via Digitalmars-d-learn 
wrote:
> Unfortunately, the minimum Windows version "officially" supported
> is Windows 7:
>
> https://forum.dlang.org/post/ktfgps$2ghh$1...@digitalmars.com
>
> With no testing on XP, you are bound to run into difficulties
> trying to use the tools there. So yeah, your best bet is using a
> compiler version that works and see if building dub from source
> makes a difference. If you can't get dub to work, then you'll
> want to look into using rdmd, which has shipped with dmd for
> years now, or perhaps makefiles.

I'm pretty sure that Phobos (and possibly druntime) use Windows API calls
that do not exist on XP and have done so for years now. You might get lucky
and get some stuff to work on XP, but not everything will work. The only way
to guarantee that it will work is to use a compiler version old enough that
XP was still supported (which probably means grabbing one from the 2013
timeframe given the date of Walter's post, though it may be possible to dig
through the changelog and find the exact version that Windows XP support was
officially dropped). However, you're not going to be able to pull in much of
anything with dub that way, because the older compiler likely won't be able
to compile the newer code, and I don't know if a version of dub that old
will ever work with the current dub repository.

- Jonathan M Davis





Re: D, Unit_Threaded, and GtkD

2020-05-18 Thread Russel Winder via Digitalmars-d-learn
On Sun, 2020-05-17 at 20:32 +, Luis via Digitalmars-d-learn wrote:
> On Sunday, 17 May 2020 at 10:19:38 UTC, Russel Winder wrote:
> > I am experimenting with using manual control of the Glib event 
> > loop using the pending and iteration methods on the default 
> > MainContext within each unit- threaded test. The alternative of 
> > running a GTK application and then putting the tests in as an 
> > asynchronous sequence only works with Rust and Python since D 
> > has no coroutines of any sort.
> > 
> 
> A Fiber can't be used for this ? D Fibers don't have a scheduler. 
> Yielding returns to the caller context.
> https://dlang.org/phobos/core_thread_fiber.html

Futures based co-routines with an executor could do it, but without some form
of scheduling, manual control is needed. In fact I think spawning an OS thread
is probably a better route, the Glib event loop can then run as it wants being
controlled via events being placed on it's queue from another thread.

-- 
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: undefined reference to 'deflateEnd'

2020-05-18 Thread ikod via Digitalmars-d-learn

On Monday, 18 May 2020 at 07:33:29 UTC, Andre Pany wrote:

On Monday, 18 May 2020 at 06:02:03 UTC, ikod wrote:

NAME="Ubuntu"
VERSION="18.04.4 LTS (Bionic Beaver)"

[...]


Thanks a lot.

Kind regards
André


Just discovered that we can import etc.c.zlib and use low level 
zlib directly


Re: undefined reference to 'deflateEnd'

2020-05-18 Thread Andre Pany via Digitalmars-d-learn

On Monday, 18 May 2020 at 06:02:03 UTC, ikod wrote:

NAME="Ubuntu"
VERSION="18.04.4 LTS (Bionic Beaver)"

[...]


Thanks a lot.

Kind regards
André


Re: Detecting performance pitfall in array access

2020-05-18 Thread Adnan via Digitalmars-d-learn

On Sunday, 17 May 2020 at 09:41:55 UTC, Johan wrote:

On Sunday, 17 May 2020 at 03:30:57 UTC, Adnan wrote:
Hello, I am trying to examine what causes my similar D 
solution to lag behind performance.


In the link, they don't have ldc or gdc but according to my 
machine, the dmd generated code isn't really far behind ldc 
generated code.


https://imgshare.io/image/NN8Xmp


Can you add `--force` to the dub commandline to make sure it is 
rebuilding the executable?


-Johan


The results stay the same. Probably some weird bug in my system.


Re: Detecting performance pitfall in array access

2020-05-18 Thread Adnan via Digitalmars-d-learn

On Sunday, 17 May 2020 at 11:39:30 UTC, kinke wrote:
As a side note, using jagged arrays for multiple dimensions 
should probably be avoided whenever you can.
By jagged array, do you mean vector of vectors? What would be an 
alternative?




Re: undefined reference to 'deflateEnd'

2020-05-18 Thread ikod via Digitalmars-d-learn

On Monday, 18 May 2020 at 05:01:45 UTC, Andre Pany wrote:

Hi,

I have some issues, the get this program working on ubuntu:

``` Dockerfile
FROM ubuntu:focal

RUN apt-get update && apt-get upgrade -y \
&& apt-get install --no-install-recommends -y 
build-essential ldc dub zlib1g-dev


COPY app.d /tmp/
RUN dub build --single /tmp/app.d -v
```

``` app.d
/+ dub.sdl:
name "app"
lflags "-lz" "-ldl"
dflags "-static"
+/
import std;
void main(){}
```

Linker fails with error messages like these:
/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libphobos2-ldc.a(zlib.o):function
 _D3std4zlib8Compress5errorMFiZv: error: undefined reference to 'deflateEnd'
/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libphobos2-ldc.a(zlib.o):function
 _D3std4zlib8Compress6__dtorMFZv: error: undefined reference to 'deflateEnd'

The actual link command looks right:
/usr/bin/ldc2 
-oftmp/.dub/build/application-debug-linux.posix-x86_64-ldc_2090-ED4668B88284A40FA4668246697CB2B5/app tmp/.dub/build/application-debug-linux.posix-x86_64-ldc_2090-ED4668B88284A40FA4668246697CB2B5/app.o -L--no-as-needed -L-lz -L-ldl -static -g


Do you have an idea?

Kind regards
André


NAME="Ubuntu"
VERSION="18.04.4 LTS (Bionic Beaver)"

Works for me on ubuntu when changed dflags to lflags:

/+ dub.sdl:
name "app"
lflags "-lz" "-ldl"
lflags "-static"
+/
import std;
void main(){}

/usr/bin/dmd -c 
-of.dub/build/application-debug-linux.posix-x86_64-dmd_2089-1D31FAC5109A6D2373EAB3139BEB0877/app.o -debug -g -w -version=Have_app t.d -vcolumns

Linking...
/usr/bin/dmd 
-of.dub/build/application-debug-linux.posix-x86_64-dmd_2089-1D31FAC5109A6D2373EAB3139BEB0877/app .dub/build/application-debug-linux.posix-x86_64-dmd_2089-1D31FAC5109A6D2373EAB3139BEB0877/app.o -L--no-as-needed -L-lz -L-ldl -L-static -g
Copying target from 
/tmp/test/.dub/build/application-debug-linux.posix-x86_64-dmd_2089-1D31FAC5109A6D2373EAB3139BEB0877/app to /tmp/test

Running ./app