Re: dlang vs crystal-language

2021-05-05 Thread Imperatorn via Digitalmars-d-learn

On Wednesday, 5 May 2021 at 18:50:05 UTC, Alain De Vos wrote:
On Friday, 30 April 2021 at 14:16:16 UTC, Vinod K Chandran 
wrote:
On Wednesday, 28 April 2021 at 22:41:03 UTC, Alain De Vos 
wrote:

[...]


Pros of **Crystal**
1. Attractive syntax. I like Ruby like syntax. It's really 
expressive.


Cons of Crystal
1. It doesn't have a compiler for Windows. It uses WSL based 
compiler and I think it's a bad idea.


I don't think I need to tell the pros & cons of **D lang** in 
it's own forum.
BTW, I wonder to see someone says that they have succeeded in 
compiling a **tkD** example code. I tried it with no luck. So 
I gave up that idea.


What's wrong with WSL. I think it is a great idea.


Maybe he meant WSL is good, but relying on it for Windows support 
is suboptimal. I kinda agree


Re: Pointer indirections

2021-05-04 Thread Imperatorn via Digitalmars-d-learn

On Tuesday, 4 May 2021 at 21:16:10 UTC, DLearner wrote:

Hi

Is there any limitation as to the number of pointer 
indirections?


I have a construct:
   a.b.c.d = x;
where all the variables are pointers to struct (the same 
struct).


This fails with 'Access Violation',
but if I change the code to:

 temp = a.b.c;
 temp.d = x;

everything seems to work.

Best regards


Code or it didn't happen 


Re: How do you compile DMD on Windows?

2021-05-02 Thread Imperatorn via Digitalmars-d-learn

On Saturday, 1 May 2021 at 22:44:34 UTC, Blatnik wrote:
I wanna hack on the compiler, but I've spend 3 hours and I 
can't get the damned thing to compile!


[...]


For me it took 3 minutes.

I opened the VS solution provided and pressed "build". Ta-daa!


Re: EMSI Containers and HashMap of HashMaps

2021-05-02 Thread Imperatorn via Digitalmars-d-learn

On Sunday, 2 May 2021 at 07:38:03 UTC, Tobias Pankrath wrote:

The following code segfaults, when the outer hashmap rehashes,
and I am not yet sure why.

```d
module tests.refcounted_hashmap_test;

import containers;
import std.typecons;

struct Map
{
HashMap!(int, int) theMap;
}

unittest
{
HashMap!(int, RefCounted!Map) mapOfMaps;
foreach (i; 0 .. 1000)
{
RefCounted!Map val;
if (i == 0) val.theMap.getOrAdd(i, i);
mapOfMaps.getOrAdd(i, val);
}
}
```

For your convenience: https://run.dlang.io/is/gHSlu1

I am using Refcounted() because HashMap itself is not 
copy-able. Is there another way to have HashMaps as values of 
HashMaps?


```d
HashMap!(int, RefCounted!Map) mapOfMaps = HashMap!(int, 
RefCounted!Map)(1024);

```


Re: serve-d and emacs

2021-05-01 Thread Imperatorn via Digitalmars-d-learn

On Friday, 30 April 2021 at 21:24:35 UTC, Christian Köstlin wrote:

On 26.04.21 21:13, WebFreak001 wrote:
On Monday, 26 April 2021 at 18:45:08 UTC, Christian Köstlin 
wrote:

Does anybody use serve-d with emacs (lsp-mode or eglot)?
I would love to see the configuration!

Kind regards,
Christian


if you configure it yourself, feel free to share the 
configuration and maybe PR it to serve-d repo.


Basic setup should be quite easy, see vim for reference: 
https://github.com/Pure-D/serve-d/blob/master/editor-vim.md
I threw together a "minimal" emacs configuration that can be 
used

if you have just a plain emacs and dlang installation.
See https://github.com/gizmomogwai/demacs

Kind regards,
Christian





Re: Thoughts on Structure

2021-04-30 Thread Imperatorn via Digitalmars-d-learn

On Friday, 30 April 2021 at 18:27:02 UTC, Alain De Vos wrote:
Is there no room for improvement to discriminate between alive 
and dead ? What do you think ?

Alive must fullfill these conditions in order to be referenced.


I and others think there's something wrong with the dub registry. 
It has stopped updating


Re: nothrow and std.exception.ifThrown

2021-04-29 Thread Imperatorn via Digitalmars-d-learn

On Thursday, 29 April 2021 at 16:02:20 UTC, novice2 wrote:

Hello.
I need use std.format.format() in nothrow function.
format() can throw.
For this case i have special default string.
I don't want embrace format into try..catch block,
and i found elegant std.exception.ifThrown.
But DMD say "ifThrown not nothrow"

https://run.dlang.io/is/kXtt5q
```d
nothrow string foo(int x, string def) {
import std.format: format;
import std.exception: ifThrown;

return format("%d", x).ifThrown(def);
}

Error: function std.exception.ifThrown!(Exception, string, 
string).ifThrown is not nothrow

```

What i can use instead of ifThrown, or how it can be changed to 
nothrow?

Thanks.


Try adding scope(failure) assert(0); in foo


Re: dlang vs crystal-language

2021-04-29 Thread Imperatorn via Digitalmars-d-learn

On Thursday, 29 April 2021 at 05:54:24 UTC, Berni44 wrote:

On Thursday, 29 April 2021 at 05:41:45 UTC, Imperatorn wrote:

Crystal has no installer for Windows


Is this a strength or a weakness? (SCNR)


lol :)

In all seriousness though. Since it a quite large population of 
the world, it's a weakness.


Re: dlang vs crystal-language

2021-04-28 Thread Imperatorn via Digitalmars-d-learn

On Wednesday, 28 April 2021 at 22:41:03 UTC, Alain De Vos wrote:
What are the strengths and weaknesses comparing the two 
languages ?
I can name a strength of dlang is the working binding to tk and 
gtk.


Crystal has no installer for Windows


Re: Visual D showing weird errors

2021-04-28 Thread Imperatorn via Digitalmars-d-learn
On Wednesday, 28 April 2021 at 06:06:47 UTC, Rainer Schuetze 
wrote:



On 26/04/2021 20:22, Imperatorn wrote:
On Monday, 26 April 2021 at 17:37:26 UTC, Rainer Schuetze 
wrote:


On 26/04/2021 10:00, Raimondo Mancino wrote:

[...]


The problem is that the semantic engine used by Visual D is 
working with the DMD frontend of 2.095, but "noreturn" is a 
new language feature introduced with 2.096.


You can filter out messages from "Intellisense" in the Error 
List window by selecting to show "Build only".


I hope I can supply a new version of Visual D with an updated 
semantic engine soon.


That would be awesome


There is a new version 1.1.1 available now with the semantic 
engine updated to dmd 2.096.1.


Splendid, thanks! Will try it out soon


Re: vibe-core sporadic internal errors

2021-04-27 Thread Imperatorn via Digitalmars-d-learn
On Tuesday, 27 April 2021 at 15:48:01 UTC, Steven Schveighoffer 
wrote:
I suspect vibe-core or event core may have some subtle bugs in 
them that are not easily repeatable, but often result in 
half-rendered web pages.


[...]


Need a full trace to be able to get anywhere I think.


Re: Windows static linking question

2021-04-27 Thread Imperatorn via Digitalmars-d-learn

On Tuesday, 27 April 2021 at 06:29:40 UTC, frame wrote:

From my source...

```d
// main.d
pragma(lib, common.lib);
extern (C) void fun(bool something);
```

[...]


Did you mean to use rdmd and not dmd? 樂


Re: Visual D showing weird errors

2021-04-26 Thread Imperatorn via Digitalmars-d-learn

On Monday, 26 April 2021 at 17:37:26 UTC, Rainer Schuetze wrote:


On 26/04/2021 10:00, Raimondo Mancino wrote:

[...]


The problem is that the semantic engine used by Visual D is 
working with the DMD frontend of 2.095, but "noreturn" is a new 
language feature introduced with 2.096.


You can filter out messages from "Intellisense" in the Error 
List window by selecting to show "Build only".


I hope I can supply a new version of Visual D with an updated 
semantic engine soon.


That would be awesome


Re: Visual D showing weird errors

2021-04-26 Thread Imperatorn via Digitalmars-d-learn

On Monday, 26 April 2021 at 11:03:19 UTC, Raimondo Mancino wrote:

On Monday, 26 April 2021 at 10:44:14 UTC, Mike Parker wrote:
You might try to build outside of VS and see if you get the 
same errors.


The weird thing is that I get these errors just in the errors 
frame, but building works just fine without errors.


If I run devenv.exe directly on the solution, or select "build" 
from the menu, it builds fine; just, I don't get autocompletion 
or go-to-definition for some symbols.


Debugging works as well (although I see mangled symbol names, 
but I guess it's how it is supposed to work).


Also, be sure to join on Discord as well 
(https://discord.gg/bMZk9Q4) if you're not already there!


Re: Visual D showing weird errors

2021-04-26 Thread Imperatorn via Digitalmars-d-learn

On Monday, 26 April 2021 at 08:00:08 UTC, Raimondo Mancino wrote:
Hello, I'm new to the language; I just started learning it a 
few months ago. I'm doing okay with it, I find it very 
versatile and fast to learn. I come from Java and C/C++ and I 
think D solves tons of problems I had with these.


[...]


What compiler and version are you using?


Re: Calling readln() after readf

2021-04-24 Thread Imperatorn via Digitalmars-d-learn

On Saturday, 24 April 2021 at 14:46:06 UTC, PinDPlugga wrote:
I didn't want to necropost, but I ran into the same behaviour 
as in this post:

https://forum.dlang.org/post/yfybveovbknvvxmio...@forum.dlang.org
and was just curious to understand it better.

[...]


https://dlang.org/library/std/string/chomp.html


Re: CTFE Assignment to anonymous union shows unexpected behavior

2021-04-23 Thread Imperatorn via Digitalmars-d-learn

On Friday, 23 April 2021 at 10:36:40 UTC, Imperatorn wrote:

On Thursday, 22 April 2021 at 22:47:17 UTC, Rekel wrote:
I'm not sure why this is happening, but after simplifying my 
code I traced it back to what the title may suggest. The 
original cause of my issues being summarized by debug print 
statements returning a union as:

[...]

Even though the nanF should thus be 1.0, 0.0, etc...

[...]


This actually seems to be a bug related to order of declaration.

Try this

---
union
{
int[size][size] b;
int[size * size] a;
}
---


Lol, formatting. But u get the idea *very* clearly at least 


Re: CTFE Assignment to anonymous union shows unexpected behavior

2021-04-23 Thread Imperatorn via Digitalmars-d-learn

On Thursday, 22 April 2021 at 22:47:17 UTC, Rekel wrote:
I'm not sure why this is happening, but after simplifying my 
code I traced it back to what the title may suggest. The 
original cause of my issues being summarized by debug print 
statements returning a union as:

[...]

Even though the nanF should thus be 1.0, 0.0, etc...

[...]


This actually seems to be a bug related to order of declaration.

Try this

---
union
{
int[size][size] b;
int[size * size] a;
}
---


Re: String concatenation segmentation error

2021-04-23 Thread Imperatorn via Digitalmars-d-learn

On Thursday, 22 April 2021 at 21:15:48 UTC, tcak wrote:

string fileContent = "";

...

[...]


Do you have a minimal reproducible test case? 樂


Re: DUB Error with packcage dformlib

2021-04-18 Thread Imperatorn via Digitalmars-d-learn

On Sunday, 18 April 2021 at 01:37:14 UTC, Marcone wrote:

I have this message when try build dub. How solve it?

Unresolvable dependencies to package dformlib
app ~master depends on dformlib ~0.2.2>


Just a comment, dforms is millions of years old. It would be nice 
to see support for it again, but I would probably choose another 
framework.


Re: How do I create classes dynamically?

2021-04-16 Thread Imperatorn via Digitalmars-d-learn

On Friday, 16 April 2021 at 18:42:35 UTC, Kagamin wrote:

On Friday, 16 April 2021 at 08:31:27 UTC, Imperatorn wrote:

One example would be a repl


That has little to do with what OP meant.


I didn't answer to that though


Re: How do I create classes dynamically?

2021-04-16 Thread Imperatorn via Digitalmars-d-learn

On Thursday, 15 April 2021 at 22:06:23 UTC, Jack wrote:

On Thursday, 15 April 2021 at 17:48:02 UTC, Imperatorn wrote:

On Thursday, 15 April 2021 at 16:39:30 UTC, Kagamin wrote:

On Wednesday, 14 April 2021 at 20:38:16 UTC, Mario wrote:

[...]


String mixins is D replacement of macros for code generation.
Works like this:
```d
mixin("class MyDynamicClassName { }");
MyDynamicClassName cls = new MyDynamicClassName;
```


Yes but not at runtime


Could you give an example of what you're trying to archive?


One example would be a repl


Re: How do I create classes dynamically?

2021-04-15 Thread Imperatorn via Digitalmars-d-learn

On Thursday, 15 April 2021 at 16:39:30 UTC, Kagamin wrote:

On Wednesday, 14 April 2021 at 20:38:16 UTC, Mario wrote:
Maybe I am just too short in D, but I wanted to find out if it 
is possible to create classes dynamically. My problem is, I 
just don't know where to start reading. Maybe at mixin 
templates?


CreateClassWithName!("MyDynamicClassName");

should create the following class to work with dynamically:

class MyDynamicClassName {
this() { writeln("I was not written, but still I exist!"); 
}

}

So that I in the end by means of

MyDynamicClassName cls = new MyDynamicClassName;


String mixins is D replacement of macros for code generation.
Works like this:
```d
mixin("class MyDynamicClassName { }");
MyDynamicClassName cls = new MyDynamicClassName;
```


Yes but not at runtime


Re: How do I create classes dynamically?

2021-04-15 Thread Imperatorn via Digitalmars-d-learn

On Wednesday, 14 April 2021 at 20:38:16 UTC, Mario wrote:
Maybe I am just too short in D, but I wanted to find out if it 
is possible to create classes dynamically. My problem is, I 
just don't know where to start reading. Maybe at mixin 
templates?


CreateClassWithName!("MyDynamicClassName");

should create the following class to work with dynamically:

class MyDynamicClassName {
this() { writeln("I was not written, but still I exist!"); }
}

So that I in the end by means of

MyDynamicClassName cls = new MyDynamicClassName;

can work with it.

Normally I would think of a macro first, but as far as I 
understood D doesn't know macros (which I'm not really sad 
about), but maybe I'm just thinking too complicated yet. I 
would appreciate any hints, because as I said, I don't even 
know where to start reading.


ldc.JIT presumably has smth like that

https://gist.github.com/eldar/2294388

Also look up ldc.dynamic_compile


Re: GC memory fragmentation

2021-04-14 Thread Imperatorn via Digitalmars-d-learn

On Wednesday, 14 April 2021 at 12:47:22 UTC, Heromyth wrote:

On Sunday, 11 April 2021 at 09:10:22 UTC, tchaloupka wrote:

Hi,
we're using vibe-d (on Linux) for a long running REST API 
server and have problem with constantly growing memory until 
system kills it with OOM killer.




The Hunt Framework is also suffering from this. We are trying 
to make a simple example to illustrate it.


I think this is a rather serious problem for a language saying 
"GC is fine" .


Is there an issue for this?


Re: Range Error

2021-04-12 Thread Imperatorn via Digitalmars-d-learn

On Monday, 12 April 2021 at 19:19:12 UTC, kdevel wrote:

On Monday, 12 April 2021 at 18:13:38 UTC, Imperatorn wrote:
[...]

[...]


D can be so much fun!

```d
import std.stdio;

[...]


Of course :D


Re: Range Error

2021-04-12 Thread Imperatorn via Digitalmars-d-learn

On Monday, 12 April 2021 at 18:01:02 UTC, kdevel wrote:

On Sunday, 11 April 2021 at 20:41:35 UTC, Bastiaan Veelo wrote:
[...]

[...]


Yes, there is a `7` where there should be an `i` on this line:
```d
   for(int i=7;7>=0;i--)
```
This will go on forever, so you get a range error as soon as 
`i < 0`.


Can't these kinds of errors be eliminated by using foreach 
loops?:


```d
Square[8][8] square;
foreach (int i, ref v; square)
{
foreach(int j, ref w; v)
{
if((isEven(i)&(j))^(!isEven(i)&&!isEven(j)))
w = new Square(Color.none, sColor.white);
else 
if((!isEven(i)&(j))^(isEven(i)&&!isEven(j)))

w = new Square(Color.none,sColor.black);
else
assert(false);

}
}
```


Yup


Re: GC memory fragmentation

2021-04-12 Thread Imperatorn via Digitalmars-d-learn

On Sunday, 11 April 2021 at 09:10:22 UTC, tchaloupka wrote:

Hi,
we're using vibe-d (on Linux) for a long running REST API 
server and have problem with constantly growing memory until 
system kills it with OOM killer.


[...]


Looks like the GC needs some love


Re: Is there a more elegant way to do this in D?

2021-04-09 Thread Imperatorn via Digitalmars-d-learn

On Thursday, 8 April 2021 at 22:27:38 UTC, Alain De Vos wrote:

So which concrete types do you give for the two auto's.


Like Paul said.

But if you really wanted to type it out:

a is int[], conv is ubyte[] and the map is lazy, so add .array 
and it evaluates to char[]







Re: Is there a more elegant way to do this in D?

2021-04-08 Thread Imperatorn via Digitalmars-d-learn

On Thursday, 8 April 2021 at 22:02:47 UTC, Alain De Vos wrote:

I resume in the 4 ways presented,

import std;
void main(){
auto a=[1,0,1,1,1,0,1,0,1,1,1,0];

string s = format!"%-(%s%)"(a);
writeln(s);

dchar[12] b = a.map!(to!string).joiner.array;
writeln(b);

auto conv = a.to!(ubyte[]);
conv[]+='0';
   writeln(cast(string)conv);

auto r = a.map!(i => cast(char)(i + '0'));
writeln(r);
}

Why do the last two ways need "auto" as type ?


auto is not a type, it's inferring the type, like var in C#. It's 
just convenient, saves you a few keystrokes.


Re: Gui toolkits alive and gui toolkits dead

2021-04-08 Thread Imperatorn via Digitalmars-d-learn

On Wednesday, 7 April 2021 at 13:00:37 UTC, Alain De Vos wrote:

I meant dlang bindings.


Is the binding dead or alive, Schrödinger's binding. Who knows...


Re: templated overload of opAssign

2021-04-05 Thread Imperatorn via Digitalmars-d-learn

On Monday, 5 April 2021 at 15:05:24 UTC, kdevel wrote:

On Sunday, 4 April 2021 at 18:05:04 UTC, tsbockman wrote:
```
[...]

[...]

[...]

[...]

```

[...]


Nice, is this documented somewhere? 樂
Maybe we could add a better error message or smth.


Re: Is dlang.slack.com down?

2021-04-04 Thread Imperatorn via Digitalmars-d-learn

On Sunday, 4 April 2021 at 11:12:36 UTC, Per Nordlöw wrote:
Trying to access https://dlang.slack.com/ hangs for minutes on 
my machine.


I'm only using the app, same thing there for you? 樂


Re: Vibe.d tutorial

2021-04-02 Thread Imperatorn via Digitalmars-d-learn

On Thursday, 4 March 2021 at 13:47:11 UTC, Imperatorn wrote:

On Monday, 1 March 2021 at 22:25:39 UTC, Rey Valeza wrote:
Hi, I wrote a tutorial on Vibe.d while trying to re-learn 
Vibe.d. I find that most of Kai Nacke's book need updating, so 
I wrote a tutorial while trying to re-learn it.


Here it is.

https://github.com/reyvaleza/vibed/commit/27ec3678f25d1dd414fae1390677397a7bc57721

I would be glad if you can give me some feedback so I can 
improve it.


Thanks!


https://github.com/reyvaleza/vibed/blob/main/Build%20Web%20Apps%20in%20Vibe.pdf


New link:
https://raw.githubusercontent.com/reyvaleza/vibed/main/BuildWebAppsinVibe.pdf


Re: Need for speed

2021-04-01 Thread Imperatorn via Digitalmars-d-learn

On Thursday, 1 April 2021 at 21:13:18 UTC, H. S. Teoh wrote:
On Thu, Apr 01, 2021 at 01:17:15PM -0700, Ali Çehreli via 
Digitalmars-d-learn wrote:

[...]

[...]

[...]


Right, but in a typical program it's unpredictable whether 
there will be unused pages after the array.




[...]

[...]

Thanks for the very interesting information; so it looks like 
most of the time spent is actually in copying array elements 
than anything else!



T


Sorting takes longer proportionally though


Re: Need for speed

2021-04-01 Thread Imperatorn via Digitalmars-d-learn

On Thursday, 1 April 2021 at 19:00:08 UTC, Berni44 wrote:

On Thursday, 1 April 2021 at 16:52:17 UTC, Nestor wrote:
I was hoping to beat my dear Python and get similar results to 
Go, but that is not the case neither using rdmd nor running 
the executable generated by dmd. I am getting values between 
350-380 ms, and 81ms in Python.


Try using ldc2 instead of dmd:

```
ldc2 -O3 -release -boundscheck=off -flto=full 
-defaultlib=phobos2-ldc-lto,druntime-ldc-lto speed.d

```

should produce much better results.


It did! Tried those flags with dmd and ldc and got the following 
(ms) for the approaches I had earlier (made two runs for each)


DMD
11
7
6
4

DMD
15
7
10
6

LDC
6
7
9
6

LDC
12
6
8
5



Re: Need for speed

2021-04-01 Thread Imperatorn via Digitalmars-d-learn

On Thursday, 1 April 2021 at 17:30:15 UTC, Chris Piker wrote:

On Thursday, 1 April 2021 at 16:52:17 UTC, Nestor wrote:
I was hoping to beat my dear Python and get similar results to 
Go, but that is not the case neither using rdmd nor running 
the executable generated by dmd. I am getting values between 
350-380 ms, and 81ms in Python.


Nice test.  I'm new to D as well and can't comment on needed 
refactoring.   To confirm your results I compiled the D example 
using:


```
gdc -O2 speed.d -o speed
```

and measured 129 ms for the D program and 63 ms for the python3 
equivalent.


I'll be keen to see how this plays out since I'm using D as a 
faster alternative to python.


I have made 4 variants of the code and get:
20 ms (mylist ~= n and mylist.sort)
8 ms (mylist[number] = n and concurrent sort)
10 ms (parallel assignment and mylist.sort)
5 ms (parallel assignment and concurrent.sort)

Also make sure you build your application in release mode, this 
made quite some difference.


Re: Need for speed

2021-04-01 Thread Imperatorn via Digitalmars-d-learn

On Thursday, 1 April 2021 at 17:30:15 UTC, Chris Piker wrote:

On Thursday, 1 April 2021 at 16:52:17 UTC, Nestor wrote:
I was hoping to beat my dear Python and get similar results to 
Go, but that is not the case neither using rdmd nor running 
the executable generated by dmd. I am getting values between 
350-380 ms, and 81ms in Python.


Nice test.  I'm new to D as well and can't comment on needed 
refactoring.   To confirm your results I compiled the D example 
using:


```
gdc -O2 speed.d -o speed
```

and measured 129 ms for the D program and 63 ms for the python3 
equivalent.


I'll be keen to see how this plays out since I'm using D as a 
faster alternative to python.


If I make more changes in D I get below 10ms


Re: Need for speed

2021-04-01 Thread Imperatorn via Digitalmars-d-learn

On Thursday, 1 April 2021 at 16:52:17 UTC, Nestor wrote:
I am a python programmer and I am enjoying Dlang and learning 
some programming insights on the way, thank everyone.


I have no formal education and also program JS and PHP.

Watching a video where a guy programs some simple code in 
Python and the same code in Go and compares speed I thought 
that could be some nice exercise for my learning path and 
successfully ported code to Dlang (hope so)


I was hoping to beat my dear Python and get similar results to 
Go, but that is not the case neither using rdmd nor running the 
executable generated by dmd. I am getting values between 
350-380 ms, and 81ms in Python.


1- I am doing something wrong in my code?
2- Do I have wrong expectations about Dlang?

Thanks in advance.

This is the video: https://www.youtube.com/watch?v=1Sban1F45jQ
This is my D code:
```
import std.stdio;
import std.random;
import std.datetime.stopwatch : benchmark, StopWatch, AutoStart;
import std.algorithm;

void main()
{
auto sw = StopWatch(AutoStart.no);
sw.start();
int[] mylist;
for (int number = 0; number < 10; ++number)
{
auto rnd = Random(unpredictableSeed);
auto n = uniform(0, 100, rnd);
mylist ~= n;
}
mylist.sort();
sw.stop();
long msecs = sw.peek.total!"msecs";
writefln("%s", msecs);
}
```

```
import time
import random

start = time.time()
mylist = []
for _ in range(10):
mylist.append(random.randint(0,100))
mylist.sort()
end = time.time()
print(f"{(end-start)*1000}ms")
```


Now when I actually read what you wrote I tested moving auto rnd 
= Random(unpredictableSeed) outside the loop and got 481 ms for 
the first version vs 34 ms for the other.


---
auto sw = StopWatch(AutoStart.no);
sw.start();
int[] mylist;

auto rnd = Random(unpredictableSeed);

for (int number = 0; number < 10; ++number)
{
auto n = uniform(0, 100, rnd);
mylist ~= n;
}

mylist.sort();
sw.stop();

long msecs = sw.peek.total!"msecs";
writefln("%s", msecs);
---

Also, one thing you could do is to parallelize for even faster 
performance. I can show you how to do that later if you want to.


Re: Need for speed

2021-04-01 Thread Imperatorn via Digitalmars-d-learn

On Thursday, 1 April 2021 at 16:52:17 UTC, Nestor wrote:
I am a python programmer and I am enjoying Dlang and learning 
some programming insights on the way, thank everyone.


[...]


Could you also post the python code for comparison?


Re: Need for speed

2021-04-01 Thread Imperatorn via Digitalmars-d-learn

On Thursday, 1 April 2021 at 17:16:06 UTC, Imperatorn wrote:

On Thursday, 1 April 2021 at 16:52:17 UTC, Nestor wrote:
I am a python programmer and I am enjoying Dlang and learning 
some programming insights on the way, thank everyone.


[...]


Could you also post the python code for comparison?


Omg I totally missed it lol 


Re: Static array initialisation

2021-04-01 Thread Imperatorn via Digitalmars-d-learn

On Wednesday, 31 March 2021 at 17:27:44 UTC, DLearner wrote:

Hi

I did:
   immutable uint  MemSize=100;  // Memory size in bytes.

// Memory Pool
   ubyte[MemSize]  MemPool = 8;

And had a look in memory.
I think the compiler set up 101 '8's, not 100 in memory.

Which I did not expect.

Best regards


It's a bit interesting though.

The behavior seems to vary a bit between compilers.

DMD:
ubyte[100] example.MemPool:
db  008h,008h,008h,008h,008h,008h,008h,008h 
;
db  008h,008h,008h,008h,008h,008h,008h,008h 
;
db  008h,008h,008h,008h,008h,008h,008h,008h 
;
db  008h,008h,008h,008h,008h,008h,008h,008h 
;
db  008h,008h,008h,008h,008h,008h,008h,008h 
;
db  008h,008h,008h,008h,008h,008h,008h,008h 
;
db  008h,008h,008h,008h,008h,008h,008h,008h 
;
db  008h,008h,008h,008h,008h,008h,008h,008h 
;
db  008h,008h,008h,008h,008h,008h,008h,008h 
;
db  008h,008h,008h,008h,008h,008h,008h,008h 
;
db  008h,008h,008h,008h,008h,008h,008h,008h 
;
db  008h,008h,008h,008h,008h,008h,008h,008h 
;
db  008h,008h,008h,008h,000h,000h,000h,000h 
;
db  000h,000h,000h,000h,000h,000h,000h,000h 
;


LDC:
ubyte[100] example.MemPool:
.zero   100,8

GDC:
ubyte[100] example.MemPool:
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8
.byte   8

As you can see, all have 100 valid values, but DMD seems to be 
aligning to a multiple.


Re: Static array initialisation

2021-03-31 Thread Imperatorn via Digitalmars-d-learn

On Wednesday, 31 March 2021 at 17:27:44 UTC, DLearner wrote:

Hi

I did:
   immutable uint  MemSize=100;  // Memory size in bytes.

// Memory Pool
   ubyte[MemSize]  MemPool = 8;

And had a look in memory.
I think the compiler set up 101 '8's, not 100 in memory.

Which I did not expect.

Best regards


When I look there are 100. What makes you think there are 101?


Re: How to parse JSON in D?

2021-03-30 Thread Imperatorn via Digitalmars-d-learn
On Monday, 29 March 2021 at 18:19:35 UTC, Steven Schveighoffer 
wrote:

On 3/29/21 1:48 PM, Imperatorn wrote:

On Monday, 29 March 2021 at 17:21:25 UTC, tastyminerals wrote:

[...]


https://youtu.be/un-bZdyumog?t=27m25s


FYI that package is here: 
https://code.dlang.org/packages/jsoniopipe


I really want to start using it, but priorities.

It should be pretty functional, but it's a bit hard to use at 
the moment (unless you just want serialization). I need to work 
on the parsing API. The benefit is it allows parsing the JSON 
without constructing some tree-like representation of the data. 
The serializer uses this directly, which makes it fast. 
Probably not as fast as asdf, but I could maybe get it there 
with some tricks.


-Steve


Omg asdf gets ~300 MB/s, I thought iopipe's 200 MB/s was fast 


Re: How to parse JSON in D?

2021-03-29 Thread Imperatorn via Digitalmars-d-learn

On Monday, 29 March 2021 at 17:21:25 UTC, tastyminerals wrote:
We need to parse a bunch of JSON files. What does D have? It 
has std.json which is strangely slower than Python json :(
Ok, we go to dub repository and search for something that is 
faster. There are basically two implementations fast.json and 
stdx.data.json. The first one refuses to work on Mac M1 chip so 
we take the stdx.data.json, go to the documentation page and 
see two three snippets on how to use the library. The code 
examples are so scarce that I feel like a person who did it was 
forced to do it out of his own will.


[...]


https://youtu.be/un-bZdyumog?t=27m25s


Re: How to parse JSON in D?

2021-03-29 Thread Imperatorn via Digitalmars-d-learn

On Monday, 29 March 2021 at 17:21:25 UTC, tastyminerals wrote:
We need to parse a bunch of JSON files. What does D have? It 
has std.json which is strangely slower than Python json :(
Ok, we go to dub repository and search for something that is 
faster. There are basically two implementations fast.json and 
stdx.data.json. The first one refuses to work on Mac M1 chip so 
we take the stdx.data.json, go to the documentation page and 
see two three snippets on how to use the library. The code 
examples are so scarce that I feel like a person who did it was 
forced to do it out of his own will.


[...]


https://code.dlang.org/search?q=json


Re: code.dlang.org package search subtly broken?

2021-03-27 Thread Imperatorn via Digitalmars-d-learn

On Saturday, 27 March 2021 at 20:36:08 UTC, bachmeier wrote:

On Saturday, 27 March 2021 at 14:53:52 UTC, Imperatorn wrote:

Yeah, the search is broken sadly. I made a PR about it some 
time ago. Partial searches doesn't work


I don't think it's Dub search that's broken, really, it's that 
Dub uses MongoDB for searches, as discussed here:


https://forum.dlang.org/post/mpeevfwstiymjzasb...@forum.dlang.org

There have been complaints about Dub search for as long as I 
can remember, but for whatever reason it's never been brought 
up to standards.


I have a fix for it but got stuck at setting up dub-registry. 
There was some config or credentiall issue or smth. Maybe I can 
try again next week


Re: code.dlang.org package search subtly broken?

2021-03-27 Thread Imperatorn via Digitalmars-d-learn

On Saturday, 27 March 2021 at 13:48:10 UTC, Brian wrote:

Hello --

When I go to https://code.dlang.org and use the search function 
on the top right corner, it usually works fine. However, there 
was one package I knew I specifically wanted (png-d) but when I 
typed png-d into the search bar, I was greeted with an error 
page, reproduced at the bottom of this message. I get this 
error whenever a hyphen is in the search query. I have not 
tested other special characters for this error.


[...]


Yeah, the search is broken sadly. I made a PR about it some time 
ago. Partial searches doesn't work


Re: Manually check struct invariants

2021-03-23 Thread Imperatorn via Digitalmars-d-learn

On Tuesday, 23 March 2021 at 22:22:12 UTC, Q. Schroll wrote:
For a class object obj, one can use assert(obj) to get its 
invariants checked. How to do this for structs?


It's called after the constructor has run and before the 
destructor is called.


It's called before entering a member function and after exiting a 
member function.


So technically you could just do like obj.writeln or whatever u 
have 


Re: Strange error

2021-03-21 Thread Imperatorn via Digitalmars-d-learn

On Sunday, 21 March 2021 at 07:18:10 UTC, Jack Applegame wrote:

Could someone please explain what is wrong with this code?

https://glot.io/snippets/fwxn2198kv

```d
import std.stdio;

struct Sample{
  void function() func1;
  void function() func2;
}

void noth(Sample smpl)() {
  smpl.func1(); // Error: expression __lambda1 is not a valid 
template value argument
  smpl.func2(); // Error: expression __lambda2 is not a valid 
template value argument

}

void main(){
  enum s = Sample(
{writeln("Hello world1");},
{writeln("Hello world2");}
  );
  s.func1();
  s.func2();
  noth!(s)();
}
```


https://forum.dlang.org/thread/mggbomxhjpglltsih...@forum.dlang.org


Re: rawRead from Pipe segfaults

2021-03-18 Thread Imperatorn via Digitalmars-d-learn

On Wednesday, 17 March 2021 at 23:08:07 UTC, kdevel wrote:
In order to watch out for lost bytes in a pipe I encountered 
this segfault.
It seems that the readEnd is already closed when rawRead = 
fread is

called (uncomment the eof line).

[...]


Have you tried "scope(exit) wait(" instead?


Re: rdmd and D equivalent for PYTHONPATH?

2021-03-17 Thread Imperatorn via Digitalmars-d-learn

On Wednesday, 17 March 2021 at 19:33:26 UTC, Chris Piker wrote:

On Wednesday, 17 March 2021 at 09:34:21 UTC, Mike Parker wrote:

[...]


Sure will, thanks for the invite to contribute in a specific 
way.


[...]


You probably already know this, just sharing:

https://atilaoncode.blog/2020/02/19/want-to-call-c-from-python-use-d/


Re: can't link a code, is it a bug or my fault?

2021-03-17 Thread Imperatorn via Digitalmars-d-learn
On Thursday, 11 March 2021 at 17:41:27 UTC, rikki cattermole 
wrote:

Try it with:

-allinst

It may just be deciding a template instance isn't required.


The error message could maybe be changed to include this? "Try 
-allinst bla bla"


Re: How to change button text color in NM_CUSTOMDRAW (Win32 API question)

2021-03-17 Thread Imperatorn via Digitalmars-d-learn
On Wednesday, 17 March 2021 at 00:51:05 UTC, Vinod K Chandran 
wrote:

On Tuesday, 16 March 2021 at 19:42:26 UTC, Imperatorn wrote:





At last, i found the answer myself. There is a  item called 
dwDrawStage in NMCUSTOMDRAW structure. If  value of dwDrawStage 
is equal to CDDS_PREERASE, call SetBkMode with transparent and 
call SetTextColor. Then draw text  with DrawText function. And 
finally, return CDRF_NOTIFYPOSTPAINT.  In short, do the color 
changing process in pre-erase stage and return 
CDRF_NOTIFYPOSTPAINT constant. As per MSDN, What this constant 
means  is,
The control will notify the parent after painting an item. 
This occurs when the dwDrawStage of the NMCUSTOMDRAW 
structure equals CDDS_PREPAINT.


Good that you solved it, that wasn't what I thought the solution 
would be 


Was more than 10 years ago since I was "the king of win api" 


Re: How to change button text color in NM_CUSTOMDRAW (Win32 API question)

2021-03-16 Thread Imperatorn via Digitalmars-d-learn

On Tuesday, 16 March 2021 at 19:15:02 UTC, Vinod K Chandran wrote:

On Tuesday, 16 March 2021 at 18:35:00 UTC, Imperatorn wrote:


I see 

Do you get CLR_INVALID in return?


That results might be wrong. So i printed them in hex. These 
are the hex results.

Set Text color result - 
Set Text color result - 0233FF66

Set Text color result - 
Set Text color result - 
Set Text color result - 0233FF66
Set Text color result - 
Set Text color result - 0233FF66

Look, the third one is CLR_INVALID.


Some info here
https://stackoverflow.com/questions/1525669/set-static-text-color-win32/1526240


Re: How to change button text color in NM_CUSTOMDRAW (Win32 API question)

2021-03-16 Thread Imperatorn via Digitalmars-d-learn

On Tuesday, 16 March 2021 at 18:27:54 UTC, Vinod K Chandran wrote:

On Tuesday, 16 March 2021 at 17:45:09 UTC, Imperatorn wrote:



Omg the pain. Are you forced to use raw win api for this?


Not at all. It's my hobby project. I choose raw win api. It's a 
fun.


I see 

Do you get CLR_INVALID in return?


Re: How to change button text color in NM_CUSTOMDRAW (Win32 API question)

2021-03-16 Thread Imperatorn via Digitalmars-d-learn

On Tuesday, 16 March 2021 at 17:26:01 UTC, Vinod K Chandran wrote:

Hi all,
I am creating a Button class with Win32 API functions. So far 
so good. I am using NM_CUSTOMDRAW message to change the back 
color of my buttons. It's really easy to change the back color 
in this way. But I can't change the text color of my button. 
This is my pseudo code.

```
uint setBtnBackColor( LPNMCUSTOMDRAW  lp) {

[...]


Omg the pain. Are you forced to use raw win api for this?


Re: Make foreach element optional

2021-03-16 Thread Imperatorn via Digitalmars-d-learn

On Tuesday, 16 March 2021 at 13:52:29 UTC, Per Nordlöw wrote:

On Tuesday, 16 March 2021 at 13:31:34 UTC, Imperatorn wrote:

foreach(0..n) could work. Why though.


When performing a side-effect n times.


Then why not just do:

auto times(alias F, T)(T number)
{
    return number.iota.each!(_ => F());
}

void f()
{
    writeln("hi");
}

n.times!(f);

?


Re: Make foreach element optional

2021-03-16 Thread Imperatorn via Digitalmars-d-learn

On Tuesday, 16 March 2021 at 12:49:13 UTC, Per Nordlöw wrote:

I find myself writing

foreach (_; 0 .. n)
doSomething(); // no using the variable `_`

.

What about relaxing the syntax to allow

foreach (; 0 .. n)

and/or

foreach (0 .. n)

?

Thereby making the `ForeachTypeList` of `AggregateForeach` in 
the grammar rule [1] optional.


[1] https://dlang.org/spec/statement.html#foreach-statement


foreach(0..n) could work. Why though.


Re: D in AI Field

2021-03-16 Thread Imperatorn via Digitalmars-d-learn

On Tuesday, 16 March 2021 at 03:33:55 UTC, Lasheen wrote:

Hello, I'm a C programmer, and now i want to migrate to D.
i work in AI field, so i have some questions about D language:

1- is D suitable for mission critical systems(such as avionics 
systems) ?

 if (true){
2- what about safety, Security and reliability of D in Embedded 
systems ?

3- what about memory issues in D if i use it in AI ?
4- is there a compiler for AI ?
};
Thank you.


https://forum.dlang.org/thread/maqboaehjhmxvtssx...@forum.dlang.org


Re: WinUI 3

2021-03-15 Thread Imperatorn via Digitalmars-d-learn

On Monday, 15 March 2021 at 22:07:35 UTC, Siemargl wrote:

On Monday, 15 March 2021 at 16:41:08 UTC, Imperatorn wrote:

Could D be used with WinUI 3?

https://docs.microsoft.com/en-us/windows/apps/winui/winui3/

Would the win32metadata help? 樂


No need to going in another dead end


?


WinUI 3

2021-03-15 Thread Imperatorn via Digitalmars-d-learn

Could D be used with WinUI 3?

https://docs.microsoft.com/en-us/windows/apps/winui/winui3/

Would the win32metadata help? 樂


Re: Why are enums with base type string not considered strings?

2021-03-14 Thread Imperatorn via Digitalmars-d-learn

On Sunday, 14 March 2021 at 10:42:17 UTC, wolframw wrote:

enum BoolEnum   : bool   { TestBool   = false }
enum CharEnum   : char   { TestChar   = 'A' }
enum StringEnum : string { TestString = "Hello" }

pragma(msg, isBoolean!BoolEnum);   // true
pragma(msg, isSomeChar!CharEnum);  // true
pragma(msg, isSomeString!StringEnum);  // false

Why does isSomeString not return true for an enum with base 
type string while
other isX functions return true for enums with an according 
base type X?
Regarding whether enums should be considered by these 
functions, I can see the
case being made one of both ways (personally, I'd say they 
should), but in the

example above it seems that different rules are applied.


May be a regression?

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


Re: Workaround to "import" an exception from a DLL

2021-03-14 Thread Imperatorn via Digitalmars-d-learn

On Sunday, 14 March 2021 at 09:35:40 UTC, frame wrote:
I know I cannot throw exceptions from a DLL, it will crash. So 
I currently use a wrapper that collects exceptions and pick it 
up if the wrapper method returns a failure state.


As I know what type of exception will be thrown, I can copy all 
important data to a new exception object and then throwing it 
in the current context.


However, I wonder if there is way to copy the exception data 
via Throwable interface direct because checking for types via 
typeid() and string comparsion is just meh.


It is possible to fetch the exception data:

// Throwable e;

// this returns null in the program (but works in a debugger 
watch):

MyExceptionObj imported = cast(MyExceptionObj)e;

// this actually works:
MyExceptionObj imported = cast(MyExceptionObj) cast(void*)e;

But for some reason throwing this object directly would crash.

Is there are way to copy the exception data in a new Throwable 
instance that can be thrown from the current context? Or can 
the runtime be tricked by overwriting the TypeInfo in memory? 
(I don't know exactly what the actual problem is.)


In the past I've used a two patterns which are kinda wierd but. 
Basically the first is returning a tuple w value and exception 
and just check it, kinda like Go. The second approach is to have 
a function u can call to get the latest ex, kinda like 
GetLastError win api


Re: Dlang spec

2021-03-13 Thread Imperatorn via Digitalmars-d-learn

On Saturday, 13 March 2021 at 11:48:47 UTC, Bastiaan Veelo wrote:

On Thursday, 11 March 2021 at 19:38:01 UTC, Imperatorn wrote:

[...]


The spec is written in ddoc format, and I thought that ddoc was 
able to output in PDF (at least at one point). It didn’t look 
very good and I’m not sure if the functionality is still there. 
I was only able to find an old initiative [1] and two old 
threads discussing the idea [2][3]. I didn’t read all that now.


[...]


Oh, I see. Yes, the best way would obviously be to generate the 
most high quality pdf possible, and maybe even version it so you 
can look at older specs. I just did it quick n dirty 


Re: Storing interfaces as void[]

2021-03-12 Thread Imperatorn via Digitalmars-d-learn

On Friday, 12 March 2021 at 17:57:06 UTC, David  Zhang wrote:

On Friday, 12 March 2021 at 17:46:22 UTC, Imperatorn wrote:

On Friday, 12 March 2021 at 17:37:43 UTC, David  Zhang wrote:

[...]


Have you tried using Variant or jsvar 
(https://code.dlang.org/packages/arsd-official%3Ajsvar)? 樂


It doesn't appear to support interfaces, see opAssign at line 
682.


It occurs to me that I.sizeof == 8 which is just enough for the 
vtbl, but not enough for an implementation ptr. Maybe it's a 
pointer to a {self, vtbl} pair? SomeClass.sizeof == 16, which 
is enough storage for both...


Did you try Variant? Seems to work for me


Re: Storing interfaces as void[]

2021-03-12 Thread Imperatorn via Digitalmars-d-learn

On Friday, 12 March 2021 at 17:37:43 UTC, David  Zhang wrote:
I want to store interfaces as untyped void[], then cast them 
back to the interface at a later time. However, it appears to 
produce garbage values on get().


Is this even possible, and if so, what is happening here? The 
alternative would be a struct { CheckedPtr self; api_fns }


e.g.

void register(I)(I i) {
  auto mem = new void[](I.sizeof);
  memcpy(mem.ptr, cast(void*) i, I.sizeof);

  // CheckedPtr includes a hash of fullyQualifiedName
  map[i.get_name()] = CheckedPtr!I(mem.ptr);
}

I get(I)() {
  // basically cast(I) p
  return map[I.get_name()].as!I();
}


Have you tried using Variant or jsvar 
(https://code.dlang.org/packages/arsd-official%3Ajsvar)? 樂


Re: Static initialization of associative arrays

2021-03-11 Thread Imperatorn via Digitalmars-d-learn

On Thursday, 11 March 2021 at 18:41:08 UTC, Ali Çehreli wrote:

On 3/11/21 10:06 AM, Chris Piker wrote:

>https://dlang.org/spec/hash-map.html#static_initialization
>
> that this feature is not yet implemented.

I use a shared static this() block:

immutable string[int] aa;

shared static this() {
  aa = [ 1: "one" ];
}

void main() {
  assert(aa.length == 1);
}

And it is possible to build an AA at compile time as the 
initial value but it still needs a trivial assigment to the 
immutable variable. Assuming that we have the following file at 
compile time named 'my_aa':


--- 8< ---
1 one
2 two
--- 8< ---

And remembering that we have to use the -J switch when 
compiling (e.g. as -J.), you can parse and build an AA from 
that file like this. (Sorry for insisting on the the range 
style; it can be done in other ways).


immutable string[int] aa;

shared static this() {
  import std.algorithm;
  import std.range;
  import std.typecons;
  import std.conv;

  enum compileTimeAA = import("my_aa")
   .splitter
   .chunks(2)
   .map!(a => tuple(a.front.to!int,
a.dropOne.front))
   .assocArray;

  aa = compileTimeAA;
}

import std.stdio;

void main() {
  writeln(aa);
}

Ali


You can however do like this (cheating):
https://run.dlang.io/is/9TSfAB

"The variable myOptions is assigned the result of the literal at 
runtime. But because it's immutable, the compiler knows what's in 
it. So it can extrapolate back to the literal what it is at 
compile time"


We had a discussion in Discord about this last week.




Re: Is it possible to suppress standard lib and dlang symbols in dylib (macos)

2021-03-11 Thread Imperatorn via Digitalmars-d-learn

On Thursday, 11 March 2021 at 17:00:06 UTC, David wrote:

On Thursday, 11 March 2021 at 14:49:32 UTC, Imperatorn wrote:

On Thursday, 11 March 2021 at 10:29:55 UTC, David wrote:

On Thursday, 11 March 2021 at 08:40:58 UTC, Imperatorn wrote:

On Thursday, 11 March 2021 at 08:34:48 UTC, David wrote:
I thought it would be fun to convert some old C++/C quant 
utils to D. I'm starting with a simple library that I call 
from vba in Excel on macos:


[...]


*trigger warning*

"vba in Excel on macos" ⚠️

Btw, have you looked at excel-d?

https://code.dlang.org/packages/excel-d



Btw, have you looked at excel-d?
Of course - but unless I've missed something I don't believe 
it works on macos.


Hmm, I'm not sure. Have you tried?


Nope the documentation implies it only works on windows so I've 
ruled it out. But the thing I'm trying to solve is suppression 
of symbols in the library.


I see, there might be something similar to .def?
https://docs.microsoft.com/en-us/cpp/build/reference/module-definition-dot-def-files?redirectedfrom=MSDN=msvc-160

Or I guess you could strip it?
https://www.linux.org/docs/man1/strip.html

But I guess you already thought of that and want to not even 
generate them in the first place?


Re: Is it possible to suppress standard lib and dlang symbols in dylib (macos)

2021-03-11 Thread Imperatorn via Digitalmars-d-learn

On Thursday, 11 March 2021 at 10:29:55 UTC, David wrote:

On Thursday, 11 March 2021 at 08:40:58 UTC, Imperatorn wrote:

On Thursday, 11 March 2021 at 08:34:48 UTC, David wrote:
I thought it would be fun to convert some old C++/C quant 
utils to D. I'm starting with a simple library that I call 
from vba in Excel on macos:


[...]


*trigger warning*

"vba in Excel on macos" ⚠️

Btw, have you looked at excel-d?

https://code.dlang.org/packages/excel-d



Btw, have you looked at excel-d?
Of course - but unless I've missed something I don't believe it 
works on macos.


Hmm, I'm not sure. Have you tried?


Re: Is it possible to suppress standard lib and dlang symbols in dylib (macos)

2021-03-11 Thread Imperatorn via Digitalmars-d-learn

On Thursday, 11 March 2021 at 08:34:48 UTC, David wrote:
I thought it would be fun to convert some old C++/C quant utils 
to D. I'm starting with a simple library that I call from vba 
in Excel on macos:


[...]


*trigger warning*

"vba in Excel on macos" ⚠️

Btw, have you looked at excel-d?

https://code.dlang.org/packages/excel-d


Re: Unary operators for Variants

2021-03-10 Thread Imperatorn via Digitalmars-d-learn

On Tuesday, 9 March 2021 at 20:05:07 UTC, Jeff wrote:
So, I can't seem to get unary operators to work with variants. 
For example:


Variant x = 10;
writeln(-x); // Error: x is not of arithmetic type, it is a 
VariantN!32LU


Obviously binary operators like + work fine. Is there a reason 
opUnary wasn't implemented as well? Is there a work-around for 
me to implement it myself outside of the VariantN class?


Thanks!


Try jsvar

https://dpldocs.info/experimental-docs/arsd.jsvar.html


Re: Broken examples

2021-03-09 Thread Imperatorn via Digitalmars-d-learn

On Tuesday, 9 March 2021 at 15:44:39 UTC, MoonlightSentinel wrote:

On Saturday, 6 March 2021 at 08:15:16 UTC, Imperatorn wrote:

Are you sure? 樂

I tried switching to dmd-beta, dmd-nightly, ldc and ldc-beta 
and none of them worked.



Yes. All of those were stuck at 2.093 due to some issues with 
Travis. We've resolved those issues over the last few days and 
automatically updated the host compilers today.


Note that the output of doc examples is apparently cached, so 
you might need to make some changes to get the actual output 
(until the cache invalidates(?) ).


Oh, I see. Thanks for fixing it! ☀️


Re: Using YMM registers causes an undefined label error

2021-03-06 Thread Imperatorn via Digitalmars-d-learn

On Saturday, 6 March 2021 at 15:40:56 UTC, Rumbu wrote:

On Saturday, 6 March 2021 at 12:15:43 UTC, Mike Parker wrote:

[...]


Where exactly is documented the extern(D) x86-64 calling 
convention? Because currently seems like a mess according to 
the dissasembly. First X parameters on stack from left to 
right, last 4 in registers. But wait, if you have less than 4 
parameters, they are passed in register. Again, WTF?


Reading this, I'm experiencing true fear for the first time in my 
life.


Re: Broken examples

2021-03-06 Thread Imperatorn via Digitalmars-d-learn

On Saturday, 6 March 2021 at 09:38:54 UTC, Ali Çehreli wrote:

On 3/6/21 12:15 AM, Imperatorn wrote:
On Saturday, 6 March 2021 at 01:30:35 UTC, MoonlightSentinel 
wrote:

[...]


Are you sure? 樂

I tried switching to dmd-beta, dmd-nightly, ldc and ldc-beta 
and none of them worked.


Are you getting the same errors with those dmd versions?

My locally installed compiler is dmd 2.094.2, which seems to be 
too old for parse's new doCount template parameter. (I look 
inside /usr/include/dmd/phobos/std/conv.d on my Linux 
installation to be sure.)


Ali


I'll check when I'm at my computer again.


Re: Using YMM registers causes an undefined label error

2021-03-06 Thread Imperatorn via Digitalmars-d-learn

On Saturday, 6 March 2021 at 10:45:08 UTC, Rumbu wrote:

On Friday, 5 March 2021 at 21:47:49 UTC, z wrote:

[...]



I just made some tests, it seems that D has invented his own 
calling convention. And it's not documented. If you decorate 
your function with extern(C) it should respect the x86-64 ABI 
conventions. This is what I got for a 7 parameters function. 
The two compilers seems to do the same thing:


[...]


What... Is this really how it's supposed to be? Makes no sense to 
not use any of the existing conventions.


Re: How to get output of piped process?

2021-03-06 Thread Imperatorn via Digitalmars-d-learn

On Wednesday, 3 March 2021 at 20:43:54 UTC, Danny Arends wrote:

On Monday, 22 February 2021 at 14:52:22 UTC, frame wrote:
On Monday, 22 February 2021 at 13:23:40 UTC, Danny Arends 
wrote:



https://github.com/DannyArends/DaNode/blob/master/danode/process.d

Danny


This example shows how easy it is to implement a non-blocking 
stream. Phobos knows this for sockets but not for pipes?


Sockets seem to be more OS independent and are way more mature 
in Phobos.


Pipes seem to have been added as an afterthought in std.process 
and std.stdio


I had to add code for windows to deal with 
non-blocking/buffering pipes, Linux uses fcntl/fileno to enable 
non-blocking


No idea why non-blocking pipes aren't in Phobos, but pipes 
should not be an afterthought but a first class citizen imho


True, we should add this ☀️


Re: Broken examples

2021-03-06 Thread Imperatorn via Digitalmars-d-learn
On Saturday, 6 March 2021 at 01:30:35 UTC, MoonlightSentinel 
wrote:

On Friday, 5 March 2021 at 22:01:37 UTC, Imperatorn wrote:

Any idea why?


The examples are compiled using an older host compiler 
(__VERSION__ is 2.093) but use features introduced in a later 
version. This will be fixed by upgrading the compiler (the 
examples are checked using current master IIRC).


Are you sure? 樂

I tried switching to dmd-beta, dmd-nightly, ldc and ldc-beta and 
none of them worked.


Broken examples

2021-03-05 Thread Imperatorn via Digitalmars-d-learn

Basically none of the examples on here compile:
https://dlang.org/library/std/conv/parse.html

Any idea why?


Re: Broken examples

2021-03-05 Thread Imperatorn via Digitalmars-d-learn

On Friday, 5 March 2021 at 22:01:37 UTC, Imperatorn wrote:

Basically none of the examples on here compile:
https://dlang.org/library/std/conv/parse.html

Any idea why?


Output:

onlineapp.d(10): Error: template `std.conv.parse` cannot deduce 
function from argument types `!(bool, string, 
cast(Flag)false)(string)`, candidates are:
/dlang/dmd/linux/bin64/../../src/phobos/std/conv.d(2183):
`parse(Target, Source)(ref Source source)`
/dlang/dmd/linux/bin64/../../src/phobos/std/conv.d(2280):
`parse(Target, Source)(ref Source s)`

  with `Target = bool,
   Source = string`
  must satisfy the following constraint:
`   isIntegral!Target`
/dlang/dmd/linux/bin64/../../src/phobos/std/conv.d(2651):
`parse(Target, Source)(ref Source source, uint radix)`
/dlang/dmd/linux/bin64/../../src/phobos/std/conv.d(2793):
`parse(Target, Source)(ref Source s)`

  with `Target = bool,
   Source = string`
  must satisfy the following constraint:
`   is(Target == enum)`
/dlang/dmd/linux/bin64/../../src/phobos/std/conv.d(2883):
`parse(Target, Source)(ref Source source)`

  with `Target = bool,
   Source = string`
  must satisfy the following constraint:
`   isFloatingPoint!Target`
onlineapp.d(10):... (6 more, -v to show) ...
onlineapp.d(13): Error: template `std.conv.parse` cannot deduce 
function from argument types `!(bool, string, 
cast(Flag)true)(string)`, candidates are:
/dlang/dmd/linux/bin64/../../src/phobos/std/conv.d(2183):
`parse(Target, Source)(ref Source source)`
/dlang/dmd/linux/bin64/../../src/phobos/std/conv.d(2280):
`parse(Target, Source)(ref Source s)`
/dlang/dmd/linux/bin64/../../src/phobos/std/conv.d(2651):
`parse(Target, Source)(ref Source source, uint radix)`
/dlang/dmd/linux/bin64/../../src/phobos/std/conv.d(2793):
`parse(Target, Source)(ref Source s)`
/dlang/dmd/linux/bin64/../../src/phobos/std/conv.d(2883):
`parse(Target, Source)(ref Source source)`

onlineapp.d(13):... (6 more, -v to show) ...
onlineapp.d(16): Error: template `std.conv.parse` cannot deduce 
function from argument types `!(bool, string, 
cast(Flag)true)(string)`, candidates are:
/dlang/dmd/linux/bin64/../../src/phobos/std/conv.d(2183):
`parse(Target, Source)(ref Source source)`
/dlang/dmd/linux/bin64/../../src/phobos/std/conv.d(2280):
`parse(Target, Source)(ref Source s)`
/dlang/dmd/linux/bin64/../../src/phobos/std/conv.d(2651):
`parse(Target, Source)(ref Source source, uint radix)`
/dlang/dmd/linux/bin64/../../src/phobos/std/conv.d(2793):
`parse(Target, Source)(ref Source s)`
/dlang/dmd/linux/bin64/../../src/phobos/std/conv.d(2883):
`parse(Target, Source)(ref Source source)`

onlineapp.d(16):... (6 more, -v to show) ...


Re: Opaque type (struct) with a static immutable fails to compile without constructor - why?

2021-03-04 Thread Imperatorn via Digitalmars-d-learn

On Thursday, 4 March 2021 at 15:19:16 UTC, frankp wrote:

On Thursday, 4 March 2021 at 14:54:11 UTC, frankp wrote:
I give up. This makes no sense. I just accept this is the work 
of gremlins. I revert to a plain alias and an enum.


Sorry for wasting your time.


Not gremlins after all. It was simply a matter of the compiler 
pointing to the wrong line. Everything makes sense now. 
Anyways, thanks for your help.


"15 minutes of gremlins" 


Re: Vibe.d tutorial

2021-03-04 Thread Imperatorn via Digitalmars-d-learn

On Monday, 1 March 2021 at 22:25:39 UTC, Rey Valeza wrote:
Hi, I wrote a tutorial on Vibe.d while trying to re-learn 
Vibe.d. I find that most of Kai Nacke's book need updating, so 
I wrote a tutorial while trying to re-learn it.


Here it is.

https://github.com/reyvaleza/vibed/commit/27ec3678f25d1dd414fae1390677397a7bc57721

I would be glad if you can give me some feedback so I can 
improve it.


Thanks!


https://github.com/reyvaleza/vibed/blob/main/Build%20Web%20Apps%20in%20Vibe.pdf


Re: Shared library module system with dub

2021-03-02 Thread Imperatorn via Digitalmars-d-learn

On Tuesday, 2 March 2021 at 00:40:06 UTC, Pillager86 wrote:
What is the correct multi-platform way to build one dub project 
as a shared library, and load said shared library in a separate 
dub project? So far I am able to load a shared library and run 
a function from it (had to extern(C) it to get the symbol to 
load) by using "targetType":"dynamicLibrary" in the shared 
library project, but the main program exits with code -11 and 
if I don't unload the library manually I get a weird "Aborting 
from src/rt/sections_elf_shared.d(500) DSO being unregistered 
isn't current last one.Program exited with code -6" error that 
Google knows nothing about.


[...]


https://www.flipcause.com/secure/cause_pdetails/ODcyMDE=


Re: tiny alternative to std library

2021-03-01 Thread Imperatorn via Digitalmars-d-learn

On Thursday, 25 February 2021 at 22:39:11 UTC, Anthony wrote:

Hello,

I noticed that importing some std libraries causes the build 
time to jump to around 1 - 3 secs.


I started creating my own helper functions to avoid importing 
std for scripting and prototyping in order to keep the compile 
time at around 0.5 secs.


I was wondering if anyone knows of any libraries that are 
geared towards something like this?


Thanks


What part of std? Have you tried selective imports?


Re: DUB is not working correctly

2021-02-24 Thread Imperatorn via Digitalmars-d-learn

On Wednesday, 24 February 2021 at 16:13:48 UTC, Maxim wrote:
Hello, I have problems with working in dub environment. If I 
try to init my project with 'dub init', all needed files will 
be created successfully. However, when I run 'dub run', the 
manager gives me an error:


[...]


Wierd, have never encountered that. I'm also using Win 10 x64.


Re: Memory allocation

2021-02-23 Thread Imperatorn via Digitalmars-d-learn

On Tuesday, 23 February 2021 at 19:44:39 UTC, David wrote:

Not sure if `learn` is the right topic or not to post this..

I've been going through Bob Nystrom's "Crafting Interpreters" 
for a bit of fun and over the weekend put together a toy 
allocator in D - free and gc not yet done. It's single threaded 
and unsurprisingly faster than malloc for small objects up to 
512 bytes, and about the same for larger objects (simulated 
with a linear distribution of size requests).


[...]


Have you looked at the "experimental" allocator(s) in D?

std.experimental.allocator


Re: How to get output of piped process?

2021-02-23 Thread Imperatorn via Digitalmars-d-learn

On Monday, 22 February 2021 at 13:23:40 UTC, Danny Arends wrote:

On Friday, 19 February 2021 at 15:39:25 UTC, kdevel wrote:

[...]


Perhaps a bit late, but this is how I deal with pipes and 
spawnShell.

Read one byte at a time from stdout and stderr:

https://github.com/DannyArends/DaNode/blob/master/danode/process.d

Danny


Interesting, do you have any benchmarks for DaNode?


Re: Why does this not pass

2021-02-23 Thread Imperatorn via Digitalmars-d-learn

On Tuesday, 23 February 2021 at 09:21:44 UTC, Imperatorn wrote:

Why does all these pass:
static assert(is(ElementEncodingType!(char[]) == char));
static assert(is(ElementEncodingType!(wstring) == 
immutable(wchar)));

static assert(is(ElementEncodingType!(byte[]) == byte));
static assert(is(ElementEncodingType!(ubyte[]) == ubyte));

auto range = iota(0, 10);
static assert(is(ElementEncodingType!(typeof(range)) == 
int));
static assert(is(ElementEncodingType!(immutable(ubyte)[]) 
== immutable(ubyte)));


But not this:
static assert(is(ElementEncodingType!(AsciiChar[]) == 
AsciiChar));


omg forgot to import std.range 

But the question is kinda still valid, like in the case of 
std.array.appender.


The original poster:
"Appender defines its element type with ElementEncodingType which 
only passes immutability through for built-in string types"


Why does this not pass

2021-02-23 Thread Imperatorn via Digitalmars-d-learn

Why does all these pass:
static assert(is(ElementEncodingType!(char[]) == char));
static assert(is(ElementEncodingType!(wstring) == 
immutable(wchar)));

static assert(is(ElementEncodingType!(byte[]) == byte));
static assert(is(ElementEncodingType!(ubyte[]) == ubyte));

auto range = iota(0, 10);
static assert(is(ElementEncodingType!(typeof(range)) == int));
static assert(is(ElementEncodingType!(immutable(ubyte)[]) == 
immutable(ubyte)));


But not this:
static assert(is(ElementEncodingType!(AsciiChar[]) == 
AsciiChar));




Re: Include http based module

2021-02-20 Thread Imperatorn via Digitalmars-d-learn

On Friday, 19 February 2021 at 19:20:39 UTC, tcak wrote:

I have written a test module and put it into /var/www/html:

module mymodule;

import std.stdio;

void testMe(){ writeln("I tested you!"); }


Then I have a main file where I would like to call the function 
"testMe".



My build line is as follows:

dmd main.d "http://localhost/mymodule.d;


Result:

Error: module mymodule is in file 'http://localhost/mymodule.d' 
which cannot be read

import path[0] = /usr/include/dmd/phobos
import path[1] = /usr/include/dmd/druntime/import


Is there any way to include http(s) based modules into 
compilation (Please do not suggest dub etc)?


If you *desperately* wanted that I guess you could map it via 
some fs-network driver or similar.


Re: How to get output of piped process?

2021-02-19 Thread Imperatorn via Digitalmars-d-learn
On Thursday, 18 February 2021 at 17:27:48 UTC, Steven 
Schveighoffer wrote:

On 2/18/21 4:40 AM, frame wrote:

[...]


It's just the way it is. Everything in Phobos is a C FILE * 
(wrapped in a File). You need to use alternative i/o systems to 
get the information.


[...]


Does your iopipe handle... Pipes? 

Like someone wrote, can it? 樂


Re: Profiling

2021-02-11 Thread Imperatorn via Digitalmars-d-learn

On Wednesday, 10 February 2021 at 23:42:31 UTC, mw wrote:

On Wednesday, 10 February 2021 at 11:52:51 UTC, JG wrote:


As a follow up question I would like to know what tool people 
use to profile d programs?


I use this one:

https://code.dlang.org/packages/profdump

e.g.

```
dub build --build=debug --build=profile

# run your program to generate trace.log

profdump -b trace.log trace.log.b
profdump -f --dot --threshold 1 trace.log trace.log.dot
echo 'view it with: xdot trace.log.dot'
```


Nice, didn't even know that existed


Re: Real simple unresolved external symbols question...

2021-02-11 Thread Imperatorn via Digitalmars-d-learn

On Thursday, 11 February 2021 at 00:18:23 UTC, H. S. Teoh wrote:
On Wed, Feb 10, 2021 at 11:35:27PM +, WhatMeWorry via 
Digitalmars-d-learn wrote: [...]

Okay, thanks. Then why does the README.md at

https://github.com/dlang/druntime

say "Runtime is typically linked together with Phobos in a 
release such that the compiler only has to link to a single 
library to provide the user with the runtime and the standard 
library."


Probably outdated information.  Somebody should submit a PR for 
it. ;-)



T


Can someone in here update the docs?


Re: Finding position of a value in an array

2021-02-06 Thread Imperatorn via Digitalmars-d-learn

On Saturday, 6 February 2021 at 15:47:05 UTC, Rumbu wrote:
On Sunday, 29 December 2019 at 08:26:58 UTC, Daren Scot Wilson 
wrote:

[...]


Just reactivating this post to tell you that I lost 15 minutes 
of my life searching for a basic way to obtain the position of 
an element in an array; Out of frustration, I ended to write my 
own indexOf function. Any library on Earth has such function 
and it's not named countUntil, nor 
giveMeTheDamnPositionOfXInThatArray.


It seems that D is specialised in finding needles in haystacks, 
not finding elements in arrays.


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


+1


Re: Minimize GC memory footprint

2021-02-06 Thread Imperatorn via Digitalmars-d-learn
On Saturday, 6 February 2021 at 09:42:38 UTC, rikki cattermole 
wrote:

On 06/02/2021 3:32 PM, frame wrote:

 [...]


This won't do anything.


 [...]


Don't forget to stdout.flush; Otherwise stuff can get caught in 
the buffer before erroring out.



[...]


Turn on the precise GC, 32bit is a bit too small of a range and 
you can get false positives like in this case (at least looks 
like it).


For reference, how does one turn on precise GC?


Re: Any tools to track heap/stack corruptions?

2021-02-03 Thread Imperatorn via Digitalmars-d-learn

On Wednesday, 3 February 2021 at 15:59:28 UTC, H. S. Teoh wrote:
On Wed, Feb 03, 2021 at 03:47:34PM +, Imperatorn via 
Digitalmars-d-learn wrote:

On Wednesday, 3 February 2021 at 14:00:23 UTC, JN wrote:
> [...]

[...]
Or dustmite? 
https://dlang.org/blog/2020/04/13/dustmite-the-general-purpose-data-reduction-tool/


Dustmite generally does not do well with errors that move 
around and/or occasionally go away when the code changes 
slightly.  It tends to misidentify the problem in such cases 
and reduce to something that isn't related to the original 
program.  It's more suitable for problems that are 100% 
reliably reproduced.  Pointer bugs / memory corruption often do 
not fall into that category.



T


Yes, Valgrind is the way to go


Re: Any tools to track heap/stack corruptions?

2021-02-03 Thread Imperatorn via Digitalmars-d-learn

On Wednesday, 3 February 2021 at 14:00:23 UTC, JN wrote:
I am dealing with some nasty issue in my code. Basically random 
unrelated lines of code are crashing with access violations, 
and if I switch from dmd to ldc the crash goes away, or crash 
comes back, or it crashes in a different spot. Seems like I am 
corrupting some memory somewhere (I interact a lot with C 
libraries). Do you know of any tools I could use to try to 
narrow it down?


I've used Application Verifier but so far it didn't point me to 
anything specific.


I don't see where exactly you're having wierd issues.

Can you use a debugger?
https://wiki.dlang.org/Debuggers

Or dustmite?
https://dlang.org/blog/2020/04/13/dustmite-the-general-purpose-data-reduction-tool/


Refactoring tools

2021-02-02 Thread Imperatorn via Digitalmars-d-learn

As the title says:

1. Are there any (automated) refactoring tools for D?
2. If not, why? (Is D still too small?)


Re: How to profile compile times of a source code?

2021-01-31 Thread Imperatorn via Digitalmars-d-learn

On Sunday, 31 January 2021 at 12:31:59 UTC, Johan Engelen wrote:

On Sunday, 31 January 2021 at 12:16:50 UTC, Imperatorn wrote:
On Saturday, 30 January 2021 at 23:34:50 UTC, Stefan Koch 
wrote:

[...]


Interesting. Is this something that we could get into dmd with 
a switch? 樂


Try LDC 1.25 (now in beta testing) with --ftime-trace. Clang 
has the same option, so you can read more about it online in 
that context. Be sure to check out the related commandline 
flags.
I recommend the Tracy UI to look at traces, because it is by 
far the fastest viewer of large traces. 
https://github.com/wolfpld/tracy


-Johan


Cool, will take a look 


Re: How to profile compile times of a source code?

2021-01-31 Thread Imperatorn via Digitalmars-d-learn

On Saturday, 30 January 2021 at 23:34:50 UTC, Stefan Koch wrote:

On Saturday, 30 January 2021 at 22:47:39 UTC, Ahmet Sait wrote:

[...]


I have a way of getting the profile data your are after.
Get the dmd_tracing_20942 branch from 
https://github.com/UplinkCoder/dmd

Compile that version of dmd.
this special version of dmd will generate a trace file which 
can be read with the included printTraceHeader tool


Interesting. Is this something that we could get into dmd with a 
switch? 樂


  1   2   >