Re: Help optimize D solution to phone encoding problem: extremely slow performace.

2024-01-21 Thread Daniel Kozak via Digitalmars-d-learn
Dne so 20. 1. 2024 21:21 uživatel Renato via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> napsal:

> On Saturday, 20 January 2024 at 19:45:19 UTC, Daniel Kozak wrote:
> > On Sat, Jan 20, 2024 at 2:11 PM Renato via Digitalmars-d-learn
> > < digitalmars-d-learn@puremagic.com> wrote:
> >
> >> Wow, fantastic feedback from lots of people, thanks so much!
> >> ...
> >>
> >> > evilrat:
> >> > There is another important difference, i quickly looked up D
> >> > associative array implementation and the search looks like
> >> > nlog(n) complexity with plain loop iteration of hashes,
> >> > whereas
> >> > rust's implementation is using "swisstable" algorithm
> >> > implementation that has packed SIMD optimized lookups, this
> >> > is
> >> > likely where the 3x speed difference comes from.
> >>
> >> I am not using the default hash implementation in Rust (which
> >> is hashbrown as you've found out). That's too slow (because
> >> it's ddos secure - still Java's hash also is and it's still
> >> faster). I had to replace that with a library called `ahash`.
> >>
> >> If you're interested in knowing more about that, please [read
> >> my blog
> >> post](https://renato.athaydes.com/posts/how-to-write-fast-rust-code)
> about optimising the Rust code.
> >>
> >> So, no, that's not where the difference is coming from... in
> >> fact, I am using a faster hashing function in D.
> >>
> >> You can [see my custom hashing function
> >> here](
> >>
> https://github.com/renatoathaydes/prechelt-phone-number-encoding/commit/d1fa1b77ad928f7d536728fba11f2d69b4afe7e3
> ).
> >> This function is not good for the general purpose case, but
> >> it's probably
> >> as good as it gets for this problem (see my int128 trick in a
> >> previous post
> >> on this thread to understand why). I did try a few variations
> >> of hashing
> >> before settling on this one... Rust, if anything, is at a
> >> disadvantage here.
> >>
> >
> > And here you are wrong, it is the hashing when the slowdown
> > comes. It is not only about the speed of hashing function. It
> > is about the quality of hashing functiuon for this particular
> > problem and it is about how hashing table (associative array)
> > is implemented.
>
> I've explained why this function is almost a perfect hash
> function for this problem (there will be almost no collisions
> except for very large inputs where the shift-left will
> "overflow", and even then the probability of collisions should be
> very low). If you're going to claim I'm wrong, you must show
> exactly where I'm wrong, and preferrably you should provide a
> faster implementation. I will even accept a theoretical
> explanation if you can give one. What I will not accept, is for
> you to call me "wrong" just because you say so. That's childish
> behaviour and uncalled for on a technical discussion.
>


If you provided info that hash is perfect, than I am sorry. I have probably
missed that in this thread my fault. Than I will need to looked into this
more carefully and do much more than just assumption.

>


Re: Help optimize D solution to phone encoding problem: extremely slow performace.

2024-01-20 Thread Daniel Kozak via Digitalmars-d-learn
On Sat, Jan 20, 2024 at 2:11 PM Renato via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> Wow, fantastic feedback from lots of people, thanks so much!
> ...
>
> > evilrat:
> > There is another important difference, i quickly looked up D
> > associative array implementation and the search looks like
> > nlog(n) complexity with plain loop iteration of hashes, whereas
> > rust's implementation is using "swisstable" algorithm
> > implementation that has packed SIMD optimized lookups, this is
> > likely where the 3x speed difference comes from.
>
> I am not using the default hash implementation in Rust (which is
> hashbrown as you've found out). That's too slow (because it's
> ddos secure - still Java's hash also is and it's still faster). I
> had to replace that with a library called `ahash`.
>
> If you're interested in knowing more about that, please [read my
> blog
> post](https://renato.athaydes.com/posts/how-to-write-fast-rust-code)
> about optimising the Rust code.
>
> So, no, that's not where the difference is coming from... in
> fact, I am using a faster hashing function in D.
>
> You can [see my custom hashing function
> here](
> https://github.com/renatoathaydes/prechelt-phone-number-encoding/commit/d1fa1b77ad928f7d536728fba11f2d69b4afe7e3).
> This function is not good for the general purpose case, but it's probably
> as good as it gets for this problem (see my int128 trick in a previous post
> on this thread to understand why). I did try a few variations of hashing
> before settling on this one... Rust, if anything, is at a disadvantage here.
>

And here you are wrong, it is the hashing when the slowdown comes. It is
not only about the speed of hashing function. It is about the quality of
hashing functiuon for this particular problem and it is about how hashing
table (associative array) is implemented.


Re: Help optimize D solution to phone encoding problem: extremely slow performace.

2024-01-19 Thread Daniel Kozak via Digitalmars-d-learn
On Fri, Jan 19, 2024 at 4:44 PM H. S. Teoh via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> Taking a look at this code:
> ...


> Try addressing the points I wrote above and see if it makes a
> difference.
>
>
I have tried it (all of it) even before you wrote it here, because I have
completely the same ideas, but to be fair it has almost zero effect on
speed.
There is my version (It still use OOP, but I have try it wit Printer and
Counter to be structs and it has no effect at all)
https://paste.ofcode.org/38vKWLS8DHRazpv6MTidRJY

The only difference in speed in the end is caused by hash implementation of
dlang associative arrays and rust HashMap, actually if you modify rust to
not used ahash it has almost same speed as D


Re: D Language Foundation Monthly Meeting Summary for November 2022

2023-01-13 Thread Daniel Kozak via Digitalmars-d-announce
Dne čt 12. 1. 2023 12:51 uživatel Mike Parker

> ...
> Next, Razvan reported he had been looking at a PR to implement
> the `throw` attribute for functions. The problem with it was that
> it potentially breaks code that uses the `getAttributes` trait
> when testing for the presence of `nothrow`. Walter said that the
> compiler internally should just view `throw` as the absence of
> `nothrow` rather than as a separate attribute. Its only purpose
> is to turn `nothrow` off, so ideally code using `getAttributes`
> shouldn't need to change at all. It's not like
> `@safe`/`@trusted`/`@system`, which is a tri-state. With the
> binary `nothrow`/`throw` state, you only need to care if a
> function is `nothrow` or not. Martin agreed.
>
> With that, Andrei brought up past debates about `attribute(true)`
> and `attribute(false)`. Walter finds that syntax clunky. It was
> easy to use `throw` to turn off `nothrow` since it's already a
> keyword. Petar brought up `pure` and `@nogc`. This led to a long
> discussion about attribute algebra, attribute soup, negative and
> positive attributes for disabling each other, attribute
> inference, circular dependencies, and tangential topics. Finally,
> Dennis gave his perspective and mentioned another proposal that
> had come up in the past: using the `default` keyword to establish
> a default set of attributes for non-templated, unannotated
> functions, which could be used to "reset" the attribute state of
> any function. Walter thought that `default` to reset state is a
> great idea, and that we should think about that before


https://wiki.dlang.org/DIP79


Re: vibe.d community/forum/whatever ?

2021-08-30 Thread Daniel Kozak via Digitalmars-d-learn
On Mon, Aug 30, 2021 at 8:20 AM bauss via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> On Monday, 30 August 2021 at 02:39:06 UTC, someone wrote:
> > https://forum.rejectedsoftware.com/groups/rejectedsoftware.vibed/
> >
> > I've been reading vibe.d tour and some documentation today to
> > get some first impressions. https://vibed.org/community pointed
> > to the link above ... but it seems it is full of crap.
>
> Just use these forums as pretty much the same people are here
> that are in the vibe.d community.
>

Maybe add a new group to the forum for vibed and redirect
https://forum.rejectedsoftware.com/groups/rejectedsoftware.vibed there


Re: Performance issue with fiber

2021-07-30 Thread Daniel Kozak via Digitalmars-d-learn
On Wed, Jul 28, 2021 at 11:41 PM hanabi1224 via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> On Wednesday, 28 July 2021 at 16:26:49 UTC, drug wrote:
> > I profiled the provided example (not `FiberScheduler`) using
> > perf. Both dmd and ldc2 gave the same result - `void
> > filterInner(int, int)` took ~90% of the run time. The time was
> > divided between:
> >   `int std.concurrency.receiveOnly!(int).receiveOnly()` - 58%
> >   `void std.concurrency.send!(int).send(std.concurrency.Tid,
> > int)` - 31%
> >
> > So most of the time is messages passing.
> >
> > Between the fibers creating took very few time. Perf output
> > contains information only of `void
> > std.concurrency.FiberScheduler.create(void delegate()).wrap()`
> > which took less than 0.5%. But I wouldn't say that I did the
> > profiling ideally so take it with a grain of salt.
>
> Very interesting findings! After making the Fiber fix, I also
> made profiling with valgrind, the result shows MessageBox related
> staff contributes to ~13.7% of total cycles, swapContex related
> staff add up to a larger percentage (My rough estimation is
>  >50%), I'd like to share the result svg but did not figure out
> how to upload here.
>

I have rewrite it to be same as dart version

import std;

void main(string[] args) {
auto n = args.length > 1 ? args[1].to!int() : 5;

auto r = new Generator!int(
{
for(auto i = 2;;i++)
yield(i);
});

for(auto i=0;i

Re: How can I allocate a int[] array on stack?

2021-03-26 Thread Daniel Kozak via Digitalmars-d-learn
On Fri, Mar 26, 2021 at 7:31 AM Daniel Kozak  wrote:

> On Fri, Mar 26, 2021 at 6:50 AM Jack via Digitalmars-d-learn <
> digitalmars-d-learn@puremagic.com> wrote:
>
>> What's the equivalent of C's VLA in D? scoped from std.typecons
>> doesn't seem to work with arrays. Should I use alloca() for my
>> array or is there something else?
>>
>
> https://dlang.org/library/std/array/static_array.html
>
Sorry I was misread this


Re: How can I allocate a int[] array on stack?

2021-03-26 Thread Daniel Kozak via Digitalmars-d-learn
On Fri, Mar 26, 2021 at 7:36 AM Daniel Kozak  wrote:

> On Fri, Mar 26, 2021 at 7:31 AM Daniel Kozak  wrote:
>
>> On Fri, Mar 26, 2021 at 6:50 AM Jack via Digitalmars-d-learn <
>> digitalmars-d-learn@puremagic.com> wrote:
>>
>>> What's the equivalent of C's VLA in D? scoped from std.typecons
>>> doesn't seem to work with arrays. Should I use alloca() for my
>>> array or is there something else?
>>>
>>
>> https://dlang.org/library/std/array/static_array.html
>>
> Sorry I was misread this
>

You can use allocator:

import std.experimental.allocator.showcase;
import std.experimental.allocator;
import std.stdio;

StackFront!4096 stackAlloc;

void main() {
int[] a = stackAlloc.makeArray!int(2);
writeln(a);
}


Re: How can I allocate a int[] array on stack?

2021-03-26 Thread Daniel Kozak via Digitalmars-d-learn
On Fri, Mar 26, 2021 at 6:50 AM Jack via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> What's the equivalent of C's VLA in D? scoped from std.typecons
> doesn't seem to work with arrays. Should I use alloca() for my
> array or is there something else?
>

https://dlang.org/library/std/array/static_array.html


Re: which free operating systems have a gtkd package?

2021-01-23 Thread Daniel Kozak via Digitalmars-d-learn
On Sat, Jan 23, 2021 at 7:15 AM dan via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> ...
> So debian 10 and ubuntu 20.4 are candidates, but i'm wondering if
> there are others.  (I tried to find gtkd on linux mint but did
> not see a package for it, but man i could sure be wrong.)
>
> Thanks in advance for any info!
>
> dan
>

Anything archlinux based (Manjaro, Arch linux, EndeavourOS, RebornOS, Artix
...), Alpine linux, Fedora and many others.

https://pkgs.org/search/?q=gtkd


Re: Directory recursive walking

2021-01-15 Thread Daniel Kozak via Digitalmars-d-learn
On Fri, Jan 15, 2021 at 10:30 AM dog2002 via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> ...
> Okay, the reason is incredibly stupid: using WinMain instead of
> main causes high memory usage. I don't know why, I use the same
> code. If I replace WinMain with main, the memory consumption is
> about 6 MB.
>

https://wiki.dlang.org/D_for_Win32


Re: Directory recursive walking

2021-01-14 Thread Daniel Kozak via Digitalmars-d-learn
On Fri, Jan 15, 2021 at 8:20 AM dog2002 via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> On Friday, 15 January 2021 at 06:56:36 UTC, dog2002 wrote:
> > On Friday, 15 January 2021 at 06:33:55 UTC, Paul Backus wrote:
> >> On Friday, 15 January 2021 at 06:31:18 UTC, Paul Backus wrote:
> >>>
> >>> You can save a little bit of memory here by allocating
> >>> tempBuffer on the stack:
> >>>
> >>> ubyte[512] tempBuffer;
> >>> _inputFile.rawRead(tempBuffer[]); // note the explicit []
> >>
> >> I made a mistake; this should be:
> >>
> >> ubyte[512] tempArray;
> >> ubyte[] tempBuffer = _inputFile.rawRead(tempArray[]);
> >>
> >> ...with the rest the same as your original version.
> >
> > Thank you so much! It saves a lot of memory!
> >
> > And one last question: why the application crashes, if I
> > allocate 1 MB array?
> >
> >>ubyte[1024000] tempBuffer;
>
> Solved:
>
> ubyte[] tempBuffer = new ubyte[1024000];
>

You can still use ubyte[1024000] tempBuffer; but you have to place it
somewhere outside recursion or use a static
static ubyte[1024000] tempBuffer;


Re: Directory recursive walking

2021-01-14 Thread Daniel Kozak via Digitalmars-d-learn
On Fri, Jan 15, 2021 at 8:00 AM dog2002 via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> On Friday, 15 January 2021 at 06:33:55 UTC, Paul Backus wrote:
> > On Friday, 15 January 2021 at 06:31:18 UTC, Paul Backus wrote:
> >>
> >> You can save a little bit of memory here by allocating
> >> tempBuffer on the stack:
> >>
> >> ubyte[512] tempBuffer;
> >> _inputFile.rawRead(tempBuffer[]); // note the explicit []
> >
> > I made a mistake; this should be:
> >
> > ubyte[512] tempArray;
> > ubyte[] tempBuffer = _inputFile.rawRead(tempArray[]);
> >
> > ...with the rest the same as your original version.
>
> Thank you so much! It saves a lot of memory!
>
> And one last question: why the application crashes, if I allocate
> 1 MB array?
>
> >ubyte[1024000] tempBuffer;
>

Because of stack overflow


Re: How to debug D on Linux

2021-01-13 Thread Daniel Kozak via Digitalmars-d-learn
On Wed, Jan 13, 2021 at 4:10 PM Roguish via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> On Wednesday, 13 January 2021 at 14:17:51 UTC, Rikki Cattermole
> wrote:
> >
> > Same thing.
>
> Clear, thanks.
>
> I'm just discovering today that DMD and LDC are two different
> compilers. I got a different impression from the following
> webpage, which claims that ldmd2 is a wrapper invoking ldc2.
>
>
> https://stackoverflow.com/questions/35515138/ldc2-vs-ldmd2-whats-the-difference
>
> Perhaps this is just a peculiarity of how D is distributed on
> Debian? I simply installed the 'ldc' package from Debian's
> official repos, and that contains both a binary called ldc2 and
> one called ldmd2.
>

There are 3 main compilers which share same frontend,
DMD (using own backend), LDC2(llvm backend) a GDC(gcc backend)

ldmd and gdmd are some wrappers to make similar interface for compiling
with any of these compilers.
So generally dmd, gdmd and ldmd2(on some distribution ldmd without 2)
should have accept same args

So calling  -arg1 -arg2 -arg3 should do the same but
with different compilers behind the scene.


Re: Our community seems to have grown, so many people are joining the Facebook group

2020-12-28 Thread Daniel Kozak via Digitalmars-d-announce
On Mon, Dec 28, 2020 at 11:45 PM Ali Çehreli via Digitalmars-d-announce <
digitalmars-d-announce@puremagic.com> wrote:

> On 12/28/20 9:31 AM, Murilo wrote:
>
>  > they thought a Facebook group was unnecessary,
>
> Not only unnecessary but divisive as well. For example, because I will
> never have a Facebook account I would never be a part of that group. So,
> can the open source community be a part of Facebook groups *without* a
> Facebook account? Even if the groups would be open to the public, why
> would advertisements be a part of a D group? (I don't want to go more
> off-topic here but I would love to discuss Facebook over your favorite
> drink.)
>
>  > but what is the biggest social media in the world? Facebook!
>
> Good for them. :)
>
> Ali


+1

I am part of a nonprofit organization (some kind of admin for my village)
which provides internet access in my town(village) and  until a few months
ago there was a page (official page of our organization) which works for
all of our members even when there has been some issue with connectivity.
Ok if the issue has been between member and organization servers it would
not work, but still work in other cases or I have been able to find out
what is wrong just by looking at that page. But now they have published
all internet outages on facebook page, so I am not aware of them. And even
all my mates from the village who do not have another internet provider.

Other issue is they have some events (I always have been part of all events
before), but because those events now are on facebook it is really hard to
me to participate

So from my point of view FB is the worst thing for community or
organization in some cases.


Re: Why is (int[int] s = int[int].init) not allowed

2020-12-22 Thread Daniel Kozak via Digitalmars-d-learn
Dne st 23. 12. 2020 1:00 uživatel Steven Schveighoffer via
Digitalmars-d-learn  napsal:

> On 12/22/20 5:44 PM, Daniel Kozak wrote:
> > On Tue, Dec 22, 2020 at 10:15 PM Andre Pany via Digitalmars-d-learn
> >  > > wrote:
> >
> > Hi,
> >
> > I am really confused, why is this valid:
> > void sample(string[string] s = string[string].init){}
> >
> > while this causes syntax errors?
> >
> > void sample_invalid1(double[string] s = double[string].init){}
> > void sample_invalid2(int[int] s = int[int].init){}
> >
> > Kind regards
> > André
> >
> >
> > As has been said this is an oddity in the grammar. But why would anyone
> > need to use this anyway?
> >
> >void sample_invalid2(int[int] s = int[int].init){}
> >
> > seems really awful to me anyway.
>
> Yeah:
>
> void sample_valid(int[int] s = null)
>
> -Steve


Yes AA.init is null per doc.

https://dlang.org/spec/hash-map.html#construction_and_ref_semantic


Re: Why is (int[int] s = int[int].init) not allowed

2020-12-22 Thread Daniel Kozak via Digitalmars-d-learn
On Tue, Dec 22, 2020 at 10:15 PM Andre Pany via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> Hi,
>
> I am really confused, why is this valid:
> void sample(string[string] s = string[string].init){}
>
> while this causes syntax errors?
>
> void sample_invalid1(double[string] s = double[string].init){}
> void sample_invalid2(int[int] s = int[int].init){}
>
> Kind regards
> André
>

As has been said this is an oddity in the grammar. But why would anyone
need to use this anyway?

  void sample_invalid2(int[int] s = int[int].init){}

seems really awful to me anyway.


Re: why is "hello".writeln considered bad?

2020-11-20 Thread Daniel Kozak via Digitalmars-d-learn
On Fri, Nov 20, 2020 at 8:55 AM Mike Parker via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> ...
> Eh, I wouldn't quite put it that way. If we're thinking of the
> same thread, one person said he thought it was a bad idea. That
> doesn't make it bad practice. It's just his opinion. I think UFCS
> is an awesome feature. And it's widely used in D code.
>

I remember days when I liked UFCS too . Unfortunately  it is not so awesome
when you use it with IDE. So I am now avoiding UFCS as much as possible
and it is a much better experience for me.


Re: Task when used on a function that takes parameters doesnt work.

2020-11-12 Thread Daniel Kozak via Digitalmars-d-learn
On Thu, Nov 12, 2020 at 4:12 PM Daniel Kozak  wrote:

> On Thu, Nov 12, 2020 at 4:05 PM Ruby The Roobster via Digitalmars-d-learn <
> digitalmars-d-learn@puremagic.com> wrote:
>
>> Here is a test that I did:
>>
>> void func(int i)
>> {
>> Thread.sleep(i.seconds);
>> }
>> void main() {
>> auto test = Task!func(3);
>> test.executeInNewThread();
>> test.yeildForce();
>> }
>>
>> This gives the following errors(I'm using Code::Blocks as an IDE
>> by the way, so this is what the IDE outputted):
>> d:\Programs\D\dmd2\windows\bin\..\..\src\phobos\std\parallelism.d|516|Error:
>> function `hello.func(int i)` is not callable using argument types `()`|
>>
>> d:\Programs\D\dmd2\windows\bin\..\..\src\phobos\std\parallelism.d|516|
>>missing argument for parameter #1: `int i`|
>>
>> hello.d|8|Error: template instance `std.parallelism.Task!(func)`
>> error instantiating|
>>
>>
>> Any fix for this?
>>
>
> You have some typos there
>
> import core.thread;
> import std.parallelism;
>
> void func(int i)
> {
> Thread.sleep(i.seconds);
> }
> void main() {
> auto test = task!(func)(3);
> test.executeInNewThread();
> test.yieldForce();
> }
>

Typos: instead of Task you should write task, instead of  yeildForce you
should write yieldForce


Re: Task when used on a function that takes parameters doesnt work.

2020-11-12 Thread Daniel Kozak via Digitalmars-d-learn
On Thu, Nov 12, 2020 at 4:05 PM Ruby The Roobster via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> Here is a test that I did:
>
> void func(int i)
> {
> Thread.sleep(i.seconds);
> }
> void main() {
> auto test = Task!func(3);
> test.executeInNewThread();
> test.yeildForce();
> }
>
> This gives the following errors(I'm using Code::Blocks as an IDE
> by the way, so this is what the IDE outputted):
> d:\Programs\D\dmd2\windows\bin\..\..\src\phobos\std\parallelism.d|516|Error:
> function `hello.func(int i)` is not callable using argument types `()`|
>
> d:\Programs\D\dmd2\windows\bin\..\..\src\phobos\std\parallelism.d|516|
>missing argument for parameter #1: `int i`|
>
> hello.d|8|Error: template instance `std.parallelism.Task!(func)`
> error instantiating|
>
>
> Any fix for this?
>

You have some typos there

import core.thread;
import std.parallelism;

void func(int i)
{
Thread.sleep(i.seconds);
}
void main() {
auto test = task!(func)(3);
test.executeInNewThread();
test.yieldForce();
}


Re: How to get address of a nested function?

2020-11-10 Thread Daniel Kozak via Digitalmars-d-learn
On Tue, Nov 10, 2020 at 11:55 AM Max Samukha via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> We can get the compile time equivalent of a member function's
> address by applying '&' to the function in a static context:
>
> struct S {
>  void foo() {}
> }
>
> enum pfoo =  // ok
>
> void main() {
>  // now we can use the pointer to create, for example, a
> delegate
>  S s;
>  void delegate() dg;
>  dg.ptr = 
>  dg.funcptr = pfoo;
>  dg();
> }
>
> However, we can't do that to a nested function:
>
> void main() {
>  void foo() {
>  }
>  enum pfoo =  // weird kind of an enum delegate;
> pfoo.funcptr can't be accessed at compile time.
> }
>
> Is there a way to get a pointer to a non-static nested function?
>

non static nested function is a delegate, so you can just assign it to
delegate like I have posted or you can du this:

import std.stdio;
void main() {
void foo() {
writeln("It works as expected");
}
enum pfoo = 

void delegate() dg;
dg.ptr = pfoo.ptr;
dg.funcptr = pfoo.funcptr;
dg();
}


Re: How to get address of a nested function?

2020-11-10 Thread Daniel Kozak via Digitalmars-d-learn
On Tue, Nov 10, 2020 at 8:50 PM Max Samukha via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> On Tuesday, 10 November 2020 at 14:36:04 UTC, Steven
> Schveighoffer wrote:
>
> >>
> >> Is there a way to get a pointer to a non-static nested
> >> function?
> >
> > I don't think you can do it at compile time. You can at runtime
> > by accessing the funcptr of the delegate.
> >
> > -Steve
>
> Thanks for the reply. I will post the issue to bugzilla.
>

Why?
It works for me

import std.stdio;
void main() {
void foo() {
writeln("It works as expected");
}
enum pfoo = 

void delegate() dg = pfoo;
dg();

}


Re: std.net.curl : Performance

2020-11-09 Thread Daniel Kozak via Digitalmars-d-learn
On Mon, Nov 9, 2020 at 9:50 PM rinfz via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> On Monday, 9 November 2020 at 20:40:59 UTC, rinfz wrote:
> > On Monday, 9 November 2020 at 19:55:07 UTC, Vino wrote:
> >> ...
> >
> > The only curl option you need to set within the loop is the
> > CurlOption.url. So your foreach block should look more like:
> >
> > foreach (...) {
> > string url = chain(apihost, only(':'), to!string(apiport),
> > apiuri).to!string;
> > https.handle.set(CurlOption.url, url);
> > https.perform();
> > scope(failure) exit(-4);
> > scope(exit) https.shutdown;
> > apidata.insert(tuple(seq, cast(string) content));
> > content = [];
> > }
> >
> > Every other line can be placed before the foreach.
>
> In fact, you don't need url in there either since it's not
> dependent on loop variables, and you don't need the scope guards
> if this is running in main (you can move them out of the loop
> too).
>
> foreach (...) {
>  https.handle.set(CurlOption.url, url);
>  https.perform();
>  apidata.insert(tuple(seq, cast(string) content));
>  content = [];
> }
>

In fact he does not need foreach. Because he use it on empty result


Re: std.net.curl : Performance

2020-11-09 Thread Daniel Kozak via Digitalmars-d-learn
Just delete it

On Mon, Nov 9, 2020 at 9:00 PM Vino via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> Hi All,
>
>Request your help to on how to improve the performance of the
> below code.
>
> import std.conv: to;
> import std.net.curl : get, HTTP, CurlOption;
> import std.parallelism: parallel;
> import std.range: chain, only;
> import std.typecons: Tuple, tuple;
>
> void main ()
> {
>   Array!(Tuple!(int,string)) apidata;
>   Row[] result;
>   string apihost = "abc.com"; int apiport = 1830; string apiuri =
> /getdata;
>   string apiuser = "user"; string apipass = "pass";
>   foreach(i, k; parallel(result,1))
>  {
>string url = chain(apihost, only(':'), to!string(apiport),
> apiuri).to!string;
>string usrpass = chain(apiuser, only(':'),
> apipass).to!string;
>auto https = HTTP();
>https.handle.set(CurlOption.buffersize, 512000);
>https.handle.set(CurlOption.userpwd, usrpass);
>https.handle.set(CurlOption.connecttimeout, 600);
>https.handle.set(CurlOption.tcp_nodelay, 1);
>https.handle.set(CurlOption.http_version, 2);
>https.handle.set(CurlOption.sslversion,  1;
>https.handle.set(CurlOption.use_ssl,  3);
>https.handle.set(CurlOption.ssl_verifypeer, 0);
>https.handle.set(CurlOption.url, url);
>https.method(HTTP.Method.get);
>https.StatusLine st;
>https.onReceiveStatusLine = (https.StatusLine st) { if
> (st.code != 200) { throw new Exception(st.reason); } };
>ubyte[] content;
>https.onReceive = (ubyte[] data) { content ~= data; return
> data.length; };
>https.perform();
>scope(failure) { https.shutdown; exit(-4); } scope(exit)
> https.shutdown;
>apidata.insert(tuple(seq, cast(string) content));
>   }
>   return apidata[].sort;
> }
>
> From,
> Vino.B
>


Re: What is the difference between enum and shared immutable?

2020-10-30 Thread Daniel Kozak via Digitalmars-d-learn
On Thu, Oct 29, 2020 at 4:13 PM H. S. Teoh via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

>
> But why can't that be treated differently from explicitly writing @safe
> on a declaration?  I mean, yeah, it's easier to implement the compiler
> that way, but ease of implementation shouldn't count against proper
> language design!
>
>
> T
>
> --
> Doubt is a self-fulfilling prophecy.
>

But what about this:

shared {
some_ type some_var;
immutable int x = 1;
}

There are many ways to define it and last time when I was looking at how
this is implemented in D frontend it was implemented as a bitmask variable
and you have no context from where it comes.
So only way would be to disallow this within lexer which I do not see as a
good options


Re: Why was new(size_t s) { } deprecated in favor of an external allocator?

2020-10-15 Thread Daniel Kozak via Digitalmars-d-learn
On Wed, Oct 14, 2020 at 10:30 PM Jack via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> What was the reasoning behind this decision?
>

https://dlang.org/deprecate.html#Class allocators and deallocators


Re: question on dub and postgresql

2020-10-05 Thread Daniel Kozak via Digitalmars-d-learn
On Mon, Oct 5, 2020 at 10:25 AM Alaindevos via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> Can I say python has pip, ruby has bundle and D has dub.
> Meaning they perform the same function ?
> Or am I wrong?
>

Yes and no. Dub is Dlang dependency solution but it is not installer as pip
is


>
> As I use unix the parameters for include and library are a real
> pain.
> I have totally no idea how to connect to a postgresql database.
> Where and how do I start to connect to a postgresql database ?
> I write a .d program to connect.
> But then I need to include the database-connection-library.d file.
> Where do I place it ?
> And link a database-connection. object file.
> How is it installed ? There is a only a git i can clone ?
> Do I need to create and edit a specific dub json config file ?
> It is very unclear how to start.
>

Yes if you want to use any of dub packages you need to add it as a
dependency to your dub.json (dub.sdl)


Re: Whats going on with this?

2020-10-03 Thread Daniel Kozak via Digitalmars-d-learn
On Sat, Oct 3, 2020 at 11:30 PM Steven Schveighoffer via
Digitalmars-d-learn  wrote:

>
>
> "StructMemberInitializers with the NonVoidInitializer syntax appear in
> the lexical order of the fields in the StructDeclaration" seems to
> suggest it will not call the constructor, but instead initialize the
> fields according to the list.
>
> The fields are not a static array, so clearly it is calling the
> constructor, and not initializing the fields.
>
> I really don't think this case is in the spec.
>
> But I know it works, for instance:
>
> Variant v = anything;
>
> If this required an explicit Variant constructor, it would be quite
> annoying.
>
> -Steve
>

Yes you are right


Re: Whats going on with this?

2020-10-03 Thread Daniel Kozak via Digitalmars-d-learn
On Sat, Oct 3, 2020 at 10:40 PM Daniel Kozak  wrote:

> I would say it is here you just need to read it carefully:
>
> https://dlang.org/spec/struct.html#static_struct_init
>
>
For case specification is change I will paste it here:
'''
If a StructInitializer is supplied, the fields are initialized by the
StructMemberInitializer syntax. StructMemberInitializers with the
Identifier : NonVoidInitializer syntax may be appear in any order, where
Identifier is the field identifier. StructMemberInitializers with the
NonVoidInitializer syntax appear in the lexical order of the fields in the
StructDeclaration.
'''

And StructMemberInitializer is defined as:

'''
StructMemberInitializer:
NonVoidInitializer
Identifier : NonVoidInitializer
'''

And NonVoidInitializer is defined as:

'''
NonVoidInitializer:
ExpInitializer
ArrayInitializer
StructInitializer
'''

And as you can see there is ArrayInitializer

And there is definition of Array literals here
https://dlang.org/spec/expression.html#array_literals

and in section 2. there is this text:

'''
By default, an array literal is typed as a dynamic array, but the element
count is known at compile time. So all array literals can be implicitly
converted to static array types.
'''


Re: Whats going on with this?

2020-10-03 Thread Daniel Kozak via Digitalmars-d-learn
On Sat, Oct 3, 2020 at 4:45 PM Steven Schveighoffer via Digitalmars-d-learn
 wrote:

> On 10/3/20 6:52 AM, claptrap wrote:
> > On Saturday, 3 October 2020 at 00:15:02 UTC, Steven Schveighoffer wrote:
> >> On 10/2/20 7:28 PM, claptrap wrote:
> >>
> >>> Why would putting in the writeln cause it to fail? Is it maybe trying
> >>> to create the foo at compile time?
> >>>
> >>
> >> Yes, it is. Any static initialization of static variables happens at
> >> compile-time.
> >>
> >> https://dlang.org/spec/declaration.html#global_static_init
> >>
> >
> > Ah.. ok, any idea why this works?
> >
> > Foo foo = [300,300];
>
> Yeah, it's calling the constructor. I agree with Adam, there's nothing
> in the spec that talks about this that I can find.
>
> -Steve
>

I would say it is here you just need to read it carefully:

https://dlang.org/spec/struct.html#static_struct_init


Re: vibe.de multiple ports.

2020-09-30 Thread Daniel Kozak via Digitalmars-d-learn
On Wed, Sep 30, 2020 at 2:40 PM seany via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> On Wednesday, 30 September 2020 at 12:29:06 UTC, Daniel Kozak
> wrote:
>
> to separate the messages from the IoT responses quickly and
> forward them to different programs, and to have the capability in
> hand, so that when later i have an idea to exploit the
> capability, I can also do it.
>

Ok as Adam said you can do something like this:

void main()
{
immutable ushort startPort = 5500;
import std.range : iota;

foreach (ushort port; iota!(ushort,ushort)(startPort, startPort + 100))
{
auto settings = new HTTPServerSettings;
settings.port = port;
settings.bindAddresses = ["::1", "127.0.0.1"];
listenHTTP(settings, );
}
runApplication();
}

void hello(HTTPServerRequest req, HTTPServerResponse res)
{
import std.conv : to;
res.writeBody(req.fullURL.port.to!string);
}


Re: vibe.de multiple ports.

2020-09-30 Thread Daniel Kozak via Digitalmars-d-learn
Dne st 30. 9. 2020 13:25 uživatel seany via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> napsal:

> Hello
>
> I am trying to use this example for a iot application:
> https://aberba.com/2018/using-vibe-d-web-interface/
>
> The code i use is:
>
> ushort port   =   5504;
>
> void main(char[][] args)
> {
>
>  auto router = new URLRouter;
>  router.post("/archive", );
>  router.get("/archive", );
>
>  auto settings = new HTTPServerSettings;
>  settings.port = port;
>  settings.bindAddresses = ["::1", "0.0.0.0"];
>  listenHTTP(settings, router);
>
>  runApplication();
> }
>
>
> This is fine. But now that we have ~ 100 IoT devices in the
> field, I would like to assign each a new port.
>

Why? I do not see any reason for that.

>


Re: HTTP frameworks benchmark focused on D libraries

2020-09-28 Thread Daniel Kozak via Digitalmars-d-announce
On Sun, Sep 27, 2020 at 12:10 PM tchaloupka via Digitalmars-d-announce <
digitalmars-d-announce@puremagic.com> wrote:

> ...
> Some results are a bit surprising, ie that even with 10 runs
> there are tests that are faster than C/dlang raw tests - as they
> should be at the top because they really don't do anything with
> HTTP handling.. And eventcore/fibers to beat raw C epoll loop
> with fibers overhead? It just seems odd..
>  ...


I do not see TCP_NODELAY anywhere in your code for raw tests, so maybe you
should try that


Re: Why private methods cant be virtual?

2020-09-22 Thread Daniel Kozak via Digitalmars-d-learn
On Tue, Sep 22, 2020 at 3:05 PM claptrap via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

>
> The thread title is...
>
> "Why private methods cant be virtual?"
>
> IE Not...
>
> "how do I override private functions in a non-polymorphic manner."
>
> And what you suggest wont work because I was asking about virtual
> functions, so I specifically want polymorphism. And FWIW it's no
> big deal I can just use protected, i wasn't looking for a
> solution, I was looking for an explanation as to why it was done
> that way. But apparently there is none.
>
>
And I did not try to show solution. It was just an answer to this part of
your response:

So final private functions can be overriden? It seems not, but
the sentence is definitely confusing if not just plain wrong.

So the reason why there is this:

"Functions marked as final may not be overridden in a derived
 class, unless they are also private"

Is because with private methods final keyword has no meaning.

And there is a reason "Why private methods cant be virtual?".
It is because it would break existing code. And because  private methods
are final it makes them fast.
 And yes compiler probably could findout that method could be made
non-virtual but I am not sure how easy is this and how it would slow down
compilation times


Re: Why private methods cant be virtual?

2020-09-22 Thread Daniel Kozak via Digitalmars-d-learn
On Tue, Sep 22, 2020 at 1:30 PM ShadoLight via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

>
>
> This is not really "overriding", it is more akin to "overloading"
>

No it is not  overloading, overloading is when you have more methods with
same name and differents params. It is overriding

> It is also not polymorphic
>
I did not say otherwise :-)


Re: Why private methods cant be virtual?

2020-09-22 Thread Daniel Kozak via Digitalmars-d-learn
On Tue, Sep 22, 2020 at 11:06 AM claptrap via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

>
> "Functions marked as final may not be overridden in a derived
> class, unless they are also private"
>
> So final private functions can be overriden? It seems not, but
> the sentence is definitely confusing if not just plain wrong.
>
> Yes they can, if you have class A in one module and class B in another
module this will work:

//a.d
class A
{
private final void overrideFun()
{
import std.stdio : writeln;
writeln("A::overrideFun");
}
}

//b.d
import a;
class B : A
{
void overrideFun()
{
import std.stdio : writeln;
writeln("B::overrideFun");
}
}

// main.d
import b;

void main(string[] args)
{
B b = new B;
b.overrideFun;
}


Re: Why private methods cant be virtual?

2020-09-22 Thread Daniel Kozak via Digitalmars-d-learn
On Tue, Sep 22, 2020 at 12:23 PM Daniel Kozak  wrote:

> ...
> void main(string[] args)
> {
> B b = new B;
> b.overrideFun;
> }
>

You can have A and B in one module too of course


Re: Why does compose from std.functional return a templated function

2020-09-16 Thread Daniel Kozak via Digitalmars-d-learn
On Wed, Sep 16, 2020 at 12:50 PM Daniel Kozak  wrote:

>
>
> On Wed, Sep 16, 2020 at 12:00 PM Jan Hönig via Digitalmars-d-learn <
> digitalmars-d-learn@puremagic.com> wrote:
>
>> ...
>>
>> My main question is why? Is there something, which I am missing,
>> that explains, why it is beneficial to return a templated
>> function?
>>
>> (maybe, because I might want to compose together templated
>> non-initialized functions?)
>
>
(maybe, because I might want to compose together templated
non-initialized functions?)

Yes


Re: Why does compose from std.functional return a templated function

2020-09-16 Thread Daniel Kozak via Digitalmars-d-learn
On Wed, Sep 16, 2020 at 12:00 PM Jan Hönig via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> ...
>
> My main question is why? Is there something, which I am missing,
> that explains, why it is beneficial to return a templated
> function?
>
> (maybe, because I might want to compose together templated
> non-initialized functions?)
>

It has to be templated because than you can alias it and use it many times
something like

import std.stdio;
import std.functional : compose;
import std.algorithm.comparison : equal;
import std.algorithm.iteration : map;
import std.array : split, array;
import std.conv : to;

alias StrArrToIntArr = compose!(array,map!(to!int), split);
void main()
{
auto str1 = "2 4 8 9";
int[] intArr = StrArrToIntArr(str1);
}


If compose would not be template it would need to store functions addresses
so it would need to have some array of functions, this would be ineffective
and need to use GC


Re: Vibe-D File Question

2020-09-11 Thread Daniel Kozak via Digitalmars-d-learn
On Fri, Sep 11, 2020 at 1:15 PM Daniel Kozak  wrote:

> On Fri, Sep 11, 2020 at 1:10 PM Selim Ozel via Digitalmars-d-learn <
> digitalmars-d-learn@puremagic.com> wrote:
>
>> It seems like rejected-software forum is flooded with spam, so I
>> decided to ask it here. Is there a way to generate a file -csv
>> for example- on the back-end and serve it to the front-end as a
>> file.
>>
>> Serve static file [1] function does this for files saved on the
>> disk. I want to be able to generate a file during runtime and
>> serve it to the client. Is this possible?
>>
>> Thanks,
>> S
>>
>>
>> [1] https://vibed.org/api/vibe.http.fileserver/serveStaticFile
>>
>>
>>
> https://vibed.org/api/vibe.http.server/HTTPServerResponse.writeBody
>

import vibe.core.core;
import vibe.http.server;


void main()
{
runWorkerTaskDist();
runApplication();
}

void wrap()
{
auto settings = new HTTPServerSettings(":8080");
settings.options |= HTTPServerOption.reusePort;
listenHTTP(settings, );
}

void fun(HTTPServerRequest req, HTTPServerResponse res) nothrow
{
try
{
res.headers["Content-Disposition"] = "filename=\"muj.csv\"";
res.writeBody("some;csv;data", "text/csv");
}
catch (Exception e)
{}
}


Re: Vibe-D File Question

2020-09-11 Thread Daniel Kozak via Digitalmars-d-learn
On Fri, Sep 11, 2020 at 1:10 PM Selim Ozel via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> It seems like rejected-software forum is flooded with spam, so I
> decided to ask it here. Is there a way to generate a file -csv
> for example- on the back-end and serve it to the front-end as a
> file.
>
> Serve static file [1] function does this for files saved on the
> disk. I want to be able to generate a file during runtime and
> serve it to the client. Is this possible?
>
> Thanks,
> S
>
>
> [1] https://vibed.org/api/vibe.http.fileserver/serveStaticFile
>
>
>
https://vibed.org/api/vibe.http.server/HTTPServerResponse.writeBody


Re: vibe.d and my first web service

2020-08-12 Thread Daniel Kozak via Digitalmars-d-learn
On Wed, Aug 12, 2020 at 3:51 PM James Blachly via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> Unfortunately the problem still occurs with Vibe.d 0.9.0
>
> IMO **this is the single most important problem to fix** for vibe.d --
> if the most basic of examples (indeed, supplied by dub itself) fails so
> spectacularly, the casual new user will not spend the time to find out
> why this is happening, but instead move on. The ctrl-C non-termination
> bug has existed since at least 2015 from what I can tell from the forums.
>
> Tangent:
>
> Does Sönke have a Patreon or the project an OpenCollective etc. ? I
> would be willing to support fixing of some of these bugs.
>
> Alternatively, could we vote on whether a web framework is worthy of
> foundation support? Having an ergonomic, workable web framework is
> absolutely essential to surviving as a language in 2020 (notable
> exception being 800# gorilla incumbents C/C++).
>

Unfortunately, I think vibe-d is dead. With every release it is worse than
before and it seems there is almost no activity. So D really need new
champion here maybe hunt will be next champion.


Re: LDC cross-module-inlining

2020-08-10 Thread Daniel Kozak via Digitalmars-d-learn
On Mon, Aug 10, 2020 at 1:15 PM Per Nordlöw via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> On Monday, 10 August 2020 at 05:54:14 UTC, Daniel Kozak wrote:
> > I am not sure but last time I checked ldc does not do cross
> > module inlinig by default, and LTO only help if your
> > ldc(druntime+phobos) are built with enabled LTO[1]
> >
> > [1]
> > https://github.com/ldc-developers/ldc/issues/2182#issuecomment-343166633
>
> Are the official LDC-releases builtin with or without LTO?
>

AFAIK only for OSX, but Arch linux ldc package is now build with  LTO
enabled


Re: LDC cross-module-inlining

2020-08-09 Thread Daniel Kozak via Digitalmars-d-learn
On Mon, Aug 10, 2020 at 12:50 AM claptrap via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:

> On Sunday, 9 August 2020 at 22:18:13 UTC, Per Nordlöw wrote:
> > ...
> If you enable link time optimisation you get cross module
> inlining,
>
> -flto=full
>
> I'm not 100% sure but I think LDC did cross module inlining by
> default at some point, then I updated the compiler and had to add
> the LTO thing. I think there is an option to enable just cross
> module inlining, but if you want speed you'll probably want to
> have LTO enabled anyway?
>

I am not sure but last time I checked ldc does not do cross module
inlinig by default, and LTO only help if your ldc(druntime+phobos) are
built with enabled LTO[1]

[1] https://github.com/ldc-developers/ldc/issues/2182#issuecomment-343166633


Re: LDC cross-module-inlining

2020-08-09 Thread Daniel Kozak via Digitalmars-d-learn
On Mon, Aug 10, 2020 at 12:20 AM Per Nordlöw via Digitalmars-d-learn <
digitalmars-d-learn@puremagic.com> wrote:
>
> Is cross-module-inlining enabled by default in LDC when compiling
> in release mode or do I have to use explicitly flag for it? I
> can't find any such flag from the output of neither
>
>  ldc2 -h
>
> nor
>
>  ldmd2 -h
>
> Johan Engelen mentioned this, then experimental, flag in his
> DConf talk from 2017 [1]
>
> [1] https://www.youtube.com/watch?v=IZY67TBZ0V4

ldc2 --help-hidden | grep cross
  --disable-demotion  - Clone
multicolor basic blocks but do not demote cross scopes
 * --enable-cross-module-inlining=  - (*)
Enable cross-module function inlining (default disabled)*
  --iterative-counter-promotion   - Allow
counter promotion across the whole loop nest.
  --jump-threading-across-loop-headers- Allow
JumpThreading to thread across loop headers, for testing
  --licm-n2-threshold=   - How
many instruction to cross product using AA
  --lsr-backedge-indexing - Enable
the generation of cross iteration indexed memops
=cross-dso-cfi-
Cross-DSO CFI
=cross-dso-cfi-
Cross-DSO CFI
  --split-dwarf-cross-cu-references   - Enable
cross-cu references in DWO files
  --x86-align-branch-boundary=

Re: vibe / CTRL+C not terminating server

2020-06-13 Thread Daniel Kozak via Digitalmars-d-learn
On Sat, Jun 13, 2020 at 9:20 PM Robert M. Münch via
Digitalmars-d-learn  wrote:
>
> After a CTRL+C I still have the server process running on OSX. Any idea?
>
> [main() INF] Listening for requests on http://[::1]:8080/
> [main() INF] Listening for requests on http://127.0.0.1:8080/
> [main() INF] Please open http://127.0.0.1:8080/ in your browser.
> ^C
> [main() INF] Received signal 2. Shutting down.
>
> After this, the server is still running.
>
> --
> Robert M. Münch
> http://www.saphirion.com
> smarter | better | faster
>

https://github.com/vibe-d/vibe-core/issues/205
https://github.com/vibe-d/vibe.d/issues/2436



Re: Rationale for accepting DIP 1028 as is

2020-05-28 Thread Daniel Kozak via Digitalmars-d-announce
On Thu, May 28, 2020 at 4:56 AM Jonathan M Davis via
Digitalmars-d-announce  wrote:
>
> As far as I can tell, Walter understands the issues but fundamentally
> disagrees with pretty much everyone else on the issue.

I do not think so, the issue is, that there could be more people who
agree with Walter (like me),
but because we agree we do not participate.

> He seems to think
> that weakening @safe is worth doing, because it will ultimately mean that
> more code will be treated as @safe and mechnically checked by the compiler,

And I believe he is right.

> whereas most everyone else thinks that weakening @safe is unacceptable.

You make bad assumptions, who is "most everyone else"? I have only see
few  members of dlang arguing about that. But there is much bigger
community around there.

> But since Walter managed to convince Atila, the DIP has been accepted.
>
> - Jonathan M Davis
>

So everything is OK right?


Re: Using Vibe.d for not HTTP

2020-05-25 Thread Daniel Kozak via Digitalmars-d-learn
On Sun, May 24, 2020 at 10:10 AM Russel Winder via Digitalmars-d-learn
 wrote:
>
> Hi,
>
> Clearly Vibe.d is mostly for people doing HTTP and HTTPS stuff. Yet it claims
> to be able to support TCP and UDP working with other protocols. However, all
> the serious examples are HTTP/HTTPS related. All the TCP and UDP examples are
> basically trivial and thus useless to me for learning.
>
> I am hoping I have just missed the page/example that does something more than
> just echo for a TCP server. If I haven't, is ther an example somewhere people
> know of that I can look at?


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


Re: Learning Vibe.d

2020-05-25 Thread Daniel Kozak via Digitalmars-d-learn
On Sun, May 24, 2020 at 10:06 AM Russel Winder via Digitalmars-d-learn
 wrote:
>
> For my purposes switching to using SIGKILL rather than SIGTERM in my tests
> seems to work with 1.9.1, so I'll go with that till 1.9.2 or 1.10.0 produces a
> fix rather than revert to 1.8.1.
>

You can use VibeHighEventPriority version in your dub as a workaround
for now, there is no need to revert to 1.8.1


Re: gzip and vibe.d

2020-05-20 Thread Daniel Kozak via Digitalmars-d-learn
On Wed, May 20, 2020 at 9:45 AM Atwork via Digitalmars-d-learn
 wrote:
>
> Is it possible to have vibe.d gzip responses?
>
> I cannot find anything in the documentation about it.
>
> I am not talking about gzipping ex. files/streams but ALL
> responses as a whole.
>
> Is there a configuration or something I need to set for it to be
> supported?

https://vibed.org/api/vibe.http.server/HTTPServerSettings.useCompressionIfPossible


Re: gzip and vibe.d

2020-05-20 Thread Daniel Kozak via Digitalmars-d-learn
https://vibed.org/api/vibe.http.server/HTTPServerSettings.useCompressionIfPossible

On Wed, May 20, 2020 at 9:45 AM Atwork via Digitalmars-d-learn
 wrote:
>
> Is it possible to have vibe.d gzip responses?
>
> I cannot find anything in the documentation about it.
>
> I am not talking about gzipping ex. files/streams but ALL
> responses as a whole.
>
> Is there a configuration or something I need to set for it to be
> supported?


Re: D and Async I/O

2020-05-11 Thread Daniel Kozak via Digitalmars-d-learn
On Mon, May 11, 2020 at 4:03 PM Russel Winder via Digitalmars-d-learn
 wrote:
>
> ...
> I notice that Hunt uses it's own library eschewing all of Phobos. Is this an
> indicator that Phobos is not suitable for networking activity?
Vibe-d do that too, But https://code.dlang.org/packages/async use
phobos socket and works well


Re: Rust, D, GTK+, and asynchronous working

2020-04-27 Thread Daniel Kozak via Digitalmars-d-learn
On Mon, Apr 27, 2020 at 11:56 AM Russel Winder via Digitalmars-d-learn
 wrote:
>
> Hi,
>
> Background: I chose to rewrite a Python/PySide2/Qt application in
> X/GTK+. After much dithering I was pushed to Rust/gtk-rs/GTK+ and set
> to it. Then I decided to do D/GtkD/GTK+ as well.
>
> Totally unscientific, biased, and indeed prejudiced result is that D is
> a nicer programming language to work with than Rust for doing GTK+
> related UIs.
>
> BUT…
>
> Now I have to add the networking.
>
> GTK+ (and therefore both gtk-rs and GtkD) has APIs for all the socket
> stuff so as to be harmonious with the Glib/GIO/GTK way of the world.
> The Big Question™ is how to add monitoring a read socket stream in the
> event loop.
>
> Qt just does it automatically as far as I can tell, but GTK+ appears
> not to. Which is totally bizarre.
>
> Rust now has async/await and futures such that you can create something
> to put on the GTK+ event loop very easily. It also has very nice tools
> for doing "reactive programming" using classic programming constructs
> that turn into event loop manangement with futures.
>
> Does D have anything similar or has it missed the "programming with
> event loops" boat. Currently I am having a hard time finding ways of
> doing what is easy with Rust/gtk-rs/GTK+ using D/GtkD/GTK+ and this is
> rather frustrating given how much nicer D is for working with GTK+ than
> Rust is.
>
>
> --
> 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
>

D does not have any builtin async/await but you can use libraries

https://code.dlang.org/packages/vibe-core
https://code.dlang.org/packages/dawait



Re: Using LDC2 on ARM

2020-03-02 Thread Daniel Kozak via Digitalmars-d-learn
On Mon, Mar 2, 2020 at 6:50 PM Severin Teona via Digitalmars-d-learn
 wrote:
>
> Hello,
>
> I am working on a project that uses a Raspberry Pi (armv7l) and
> the latest LDC version I found for this architecture is 1.13.0.
> Can you help me install the latest version(1.20.0)?
>
> Also, I'm having problems using the DPP package with the 1.13.0
> LDC version, most likely because the latest version of DPP(0.4.1)
> is using a newer version of Phobos.
>
> Is there any reason why the LDC team stopped releasing pre-built
> binaries for arm?
>
> I'm looking forward to your help.
> Teona.

Do you really need to build you app on arm, could not you use crosscompiling?


Re: Using LDC2 on ARM

2020-03-02 Thread Daniel Kozak via Digitalmars-d-learn
On Mon, Mar 2, 2020 at 7:40 PM Daniel Kozak  wrote:
>
> On Mon, Mar 2, 2020 at 6:50 PM Severin Teona via Digitalmars-d-learn
> Do you really need to build you app on arm, could not you use crosscompiling?

https://wiki.dlang.org/Cross-compiling_with_LDC


Re: Using LDC2 on ARM

2020-03-02 Thread Daniel Kozak via Digitalmars-d-learn
On Mon, Mar 2, 2020 at 7:40 PM Daniel Kozak  wrote:
>
> On Mon, Mar 2, 2020 at 6:50 PM Severin Teona via Digitalmars-d-learn
>  wrote:
> >
> > Hello,
> >
> > I am working on a project that uses a Raspberry Pi (armv7l) and
> > the latest LDC version I found for this architecture is 1.13.0.
> > Can you help me install the latest version(1.20.0)?
> >
> > Also, I'm having problems using the DPP package with the 1.13.0
> > LDC version, most likely because the latest version of DPP(0.4.1)
> > is using a newer version of Phobos.
> >
> > Is there any reason why the LDC team stopped releasing pre-built
> > binaries for arm?
> >
> > I'm looking forward to your help.
> > Teona.
>
> Do you really need to build you app on arm, could not you use crosscompiling?

But if you really wan to compile it on RPI you could try use
archlinuxarm and ldc package:
https://archlinuxarm.org/packages/armv7h/ldc


Re: GtkD on Windows: notes + question

2020-02-09 Thread Daniel Kozak via Digitalmars-d-learn
"lflags-windows": ["/SUBSYSTEM:WINDOWS", "/ENTRY:mainCRTStartup"],

On Sun, Feb 9, 2020 at 2:30 PM mark via Digitalmars-d-learn
 wrote:
>
> I found a much easier way to get GtkD working on windows than
> that described in
> https://gtkdcoding.com/2019/01/11/-introduction-to-gtkDcoding.html
>
> 1. I downloaded and installed the Gtk3 runtime (the link is on
> https://gtkdcoding.com/2019/01/11/-introduction-to-gtkDcoding.html)
>
> 2. I downloaded and unzipped the GtkD3 zip to C:\bin\GtkD3
>
> 3. Since I'd already installed LDC I just had to run:
>
>  dub add-path C:\bin\GtkD3
>
> Now I'm able to build and run on windows using dub. And again, I
> get static builds so have deployable .exes.
>
> However, when I double-click a GtkD .exe it pops up a console
> window, then the GUI window, and the console window stays until I
> close the GUI.
>
> Is there a way to avoid the console Window, at least for release
> builds?
>


Re: during: a io_uring wrapper library

2019-12-09 Thread Daniel Kozak via Digitalmars-d-announce

On Sunday, 8 December 2019 at 10:35:24 UTC, tchaloupka wrote:
As of Linux kernel 5.1 new promissing io_uring interface was 
introduced (see introduction document 
https://kernel.dk/io_uring.pdf).


During[1] is a low level wrapper directly around Linux


https://bitbucket.org/kozzi11/during_io/src/master/




Re: ints.choice vs. chars.choice

2019-11-18 Thread Daniel Kozak via Digitalmars-d-learn
On Mon, Nov 18, 2019 at 7:25 PM Steven Schveighoffer via
Digitalmars-d-learn  wrote:
>
>
> You could also use cast(dchar[]), and avoid the cast back to char.
>
> -Steve

or use byCodeUnit

writeln(['a', 'b', 'c'].byCodeUnit.choice);


Re: Alias sleep(int) for Thread.sleep(dur!("seconds")( int ));

2019-11-12 Thread Daniel Kozak via Digitalmars-d-learn
On Tue, Nov 12, 2019 at 11:50 PM Marcone via Digitalmars-d-learn
 wrote:
>
>
> Can you make Alias for:
> task!func().executeInNewThread();
>
> Thank you!

AFAIK that is not possible without some wrapper because
executeInNewThread is member function of Task so it will need this
reference for object


Re: Alias sleep(int) for Thread.sleep(dur!("seconds")( int ));

2019-11-12 Thread Daniel Kozak via Digitalmars-d-learn

On Tuesday, 12 November 2019 at 21:24:54 UTC, Marcone wrote:
I am using this function to sleep, but I want a simple Alias. 
How can I alias this?


// Function sleep(int)
void sleep(int seconds){
Thread.sleep(dur!("seconds")( seconds ));
}

sleep(1); // Using function.


You can do this:

import std.functional;
import core.time;
import core.thread;

alias sleep = compose!(Thread.sleep, dur!("seconds"));

void main()
{
sleep(10);
}


Re: D for microservices: ldc, rdmd, dub now available on Alpine x86_64

2019-11-05 Thread Daniel Kozak via Digitalmars-d-announce
On Tue, Nov 5, 2019 at 12:05 PM Dejan Lekic via Digitalmars-d-announce
 wrote:
>
> On Tuesday, 5 November 2019 at 02:16:28 UTC, Mathias Lang wrote:
> > Hi all,
> > Recently there have been inquiries about support for D on
> > Alpine Linux, a distribution mostly used in combination with
> > Docker to create lightweight container images for microservices.
> >
> > At BPF Korea, we're working on a blockchain written in D, and
> > wanted to be able to easily test and distribute our node using
> > Alpine images, but there was no package for it yet.
>
> I am confused... Why do you need LDC, DMD, dub, etc on Alpine?
> Can't you build it anywhere and just put the final artifact (or
> set of artifacts) inside an Alpine-based container?

Generally no, because Apline use musl libc instead of glibc, so there
are some issues with that


Re: Hum humm, build latest release with ldc

2019-11-04 Thread Daniel Kozak via Digitalmars-d-learn
On Mon, Nov 4, 2019 at 10:45 AM Treebeard via Digitalmars-d-learn
 wrote:
>
> Hoom, hum, can you tell me some nice instructions to compile the
> latest release of DMD using LDC?
>
> I walk slowly, but I love fast compilers.
>
> ---
> But I spoke hastily. We must not be hasty. I have become too hot.
> I must cool myself and think; for it is easier to shout stop!
> than to do it - The Two Towers

https://git.archlinux.org/svntogit/community.git/tree/repos/community-x86_64/PKGBUILD?h=packages/dmd=344d0f94265571a55ca8213882151a5910bc4400#n54


Re: Accuracy of floating point calculations

2019-10-29 Thread Daniel Kozak via Digitalmars-d-learn
On Tue, Oct 29, 2019 at 5:09 PM Daniel Kozak  wrote:
>
> On Tue, Oct 29, 2019 at 4:45 PM Twilight via Digitalmars-d-learn
>  wrote:
> >
> > D calculation:
> >mport std.stdio;
import std.math : pow;
import core.stdc.math;

void main()
{
 writefln("%12.3F",log(1-0.)/log(1-(1-0.6)^^20));
}
> >writefln("%12.2F",log(1-0.)/log(1-(1-0.6)^^20));
> >
> > 837675572.38
> >
> > C++ calculation:
> >
> >cout< > <<'\n';
> >
> > 837675573.587
> >
> > As a second data point, changing 0. to 0.75 yields
> > 126082736.96 (Dlang) vs 126082737.142 (C++).
> >
> > The discrepancy stood out as I was ultimately taking the ceil of
> > the results and noticed an off by one anomaly. Testing with
> > octave, www.desmos.com/scientific, and libreoffice(calc) gave
> > results consistent with the C++ result. Is the dlang calculation
> > within the error bound of what double precision should yield?
>
> If you use gdc or ldc you will get same results as c++, or you can use
> C log directly:
>
> import std.stdio;
> import std.math : pow;
> import core.stdc.math;
>
> void main()
> {
>  writefln("%12.3F",log(1-0.)/log(1-(1-0.6)^^20));
> }

My fault, for ldc and gdc you will get same result as C++ only when
you use pow not ^^(operator) and use doubles:

import std.stdio;
import std.math;

void main()
{
 writefln("%12.3F",log(1-0.)/log((1-pow(1-0.6,20;
}


Re: Accuracy of floating point calculations

2019-10-29 Thread Daniel Kozak via Digitalmars-d-learn
On Tue, Oct 29, 2019 at 5:09 PM Daniel Kozak  wrote:
>
>
> If you use gdc or ldc you will get same results as c++, or you can use
> C log directly:
>
> import std.stdio;
> import std.math : pow;
> import core.stdc.math;
>
> void main()
> {
>  writefln("%12.3F",log(1-0.)/log(1-(1-0.6)^^20));
> }

AFAIK dmd use real  for floating point operations instead of double


Re: Accuracy of floating point calculations

2019-10-29 Thread Daniel Kozak via Digitalmars-d-learn
On Tue, Oct 29, 2019 at 4:45 PM Twilight via Digitalmars-d-learn
 wrote:
>
> D calculation:
>
>writefln("%12.2F",log(1-0.)/log(1-(1-0.6)^^20));
>
> 837675572.38
>
> C++ calculation:
>
>cout< <<'\n';
>
> 837675573.587
>
> As a second data point, changing 0. to 0.75 yields
> 126082736.96 (Dlang) vs 126082737.142 (C++).
>
> The discrepancy stood out as I was ultimately taking the ceil of
> the results and noticed an off by one anomaly. Testing with
> octave, www.desmos.com/scientific, and libreoffice(calc) gave
> results consistent with the C++ result. Is the dlang calculation
> within the error bound of what double precision should yield?

If you use gdc or ldc you will get same results as c++, or you can use
C log directly:

import std.stdio;
import std.math : pow;
import core.stdc.math;

void main()
{
 writefln("%12.3F",log(1-0.)/log(1-(1-0.6)^^20));
}


Re: Running unittests of a module with -betterC

2019-10-28 Thread Daniel Kozak via Digitalmars-d-learn
On Mon, Oct 28, 2019 at 9:40 AM Per Nordlöw via Digitalmars-d-learn
 wrote:
>
> Is it possible to run the unittests of a module with -betterC like
>
>  dmd -D -g -main -unittest -betterC f.d
>
> ?
>
> This currently errors as
>
> /usr/include/dmd/druntime/import/core/internal/entrypoint.d:34:
> error: undefined reference to '_d_run_main'
>
> for an empty file f.d

AFAIK no,

https://dlang.org/spec/betterc.html#unittests



Re: Converting a ulong to a byte array and constructing a ulong from it

2019-10-24 Thread Daniel Kozak via Digitalmars-d-learn
On Thu, Oct 24, 2019 at 3:35 PM 9898287 via Digitalmars-d-learn
 wrote:
>
> What's the function for converting a ulong to a native-endian
> byte array?
> For example,
>
> auto bytes = 0x1234567890123456u64.to_ne_bytes();
> // should yield
> // [0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56] in big-endian
> and
> // [0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12] in
> little-endian systems
>
> Also, what's the function for constructing a ulong from a
> native-endian byte array?
> For example,
>
> auto value = from_be_bytes!ulong([0x12, 0x34, 0x56, 0x78, 0x90,
> 0x12, 0x34, 0x56]);
> // value is 0x1234567890123456
>
> Rust equivalent:
> https://doc.rust-lang.org/std/primitive.u64.html#method.to_ne_bytes

You could use

https://dlang.org/phobos/std_bitmanip.html#write
https://dlang.org/phobos/std_bitmanip.html#read


Re: Differences between two dates (in days...)

2019-10-24 Thread Daniel Kozak via Digitalmars-d-learn
On Thu, Oct 24, 2019 at 1:55 PM Mil58 via Digitalmars-d-learn
 wrote:
>
> Hi All...
> I am desperate for the answer to the following problem:
> to obtain the difference between the date of today and an older
> date (results in days...)
>
> See my script below, where I would like to do:
> "date of today" (var: auj) - "an older date" (var: deb) = xx days
>
> import std.stdio;
> import std.datetime;
> import core.time : Duration;
>
> void main()
> {
> auto deb = DateTime(2019, 9, 5);
> auto auj = Clock.currTime();
> writeln("Aujourd'hui : ", auj.day, " ", auj.month, " ", auj.year);
> writeln("Le début : ", deb.day, " ", deb.month, " ", deb.year);
> }
>
> Thanks in advance !  :-)

import std.stdio;
import std.datetime;
import core.time : Duration;

void main()
{
auto deb = DateTime(2019, 9, 5);
auto auj = Clock.currTime();
writeln("Aujourd'hui : ", auj.day, " ", auj.month, " ", auj.year);
writeln("Le début : ", deb.day, " ", deb.month, " ", deb.year);
writeln("Diff in days : ", (cast(DateTime)auj - deb).total!"days");
}



Re: How to use classes from another d files

2019-10-22 Thread Daniel Kozak via Digitalmars-d-learn
On Tue, Oct 22, 2019 at 8:30 PM Vinod K Chandran via
Digitalmars-d-learn  wrote:
>
> On Tuesday, 22 October 2019 at 17:38:58 UTC, Adam D. Ruppe wrote:
> > On Tuesday, 22 October 2019 at 17:34:51 UTC, Vinod K Chandran
> > wrote:
> >> Hi all,
> >> I am new to D. But some fair experience with vb.net. I was
> >> playing with D classes.  I wrote a class in a D file.
> >> The file name is "classFile.d"
> >
> > did you compile with dmd -i or list both files on the dmd
> > command line?
>
> Thanks for the reply. Nope. I just typed this code in VS Code and
> hit the run button. Thats all. i think this cmd business will be
> difficult for me.

You should use dub. You will probably need it anyway in the future.

VS Code have nice plugins to work with D
you can install D Language utility extension pack


Re: undefined symbol: _D3std7variant...

2019-10-22 Thread Daniel Kozak via Digitalmars-d-learn
On Tue, Oct 22, 2019 at 2:20 PM Andrey via Digitalmars-d-learn
 wrote:
>
> Hello,
> During compilation on linking stage I get strange errors (LDC):
> lld-link: error: undefined symbol:
> _D3std7variant__T8VariantNVmi56TSQBf8typecons__T5TupleTAyuTSQCgQCf__TQCaVmi32TSQCzQBu__TQBoTAQBmTQBqZQCbTQnTQCbZQDrZQCqTQBcTQCrZQEh4typeMxFNbNdNeZC8TypeInfo
> >>> referenced by E:\Programs\LDC2\import\std\variant.d:753
> >>>
> >>> .dub\obj\builder.obj:(_D3std7variant__T8VariantNVmi56TSQBf8typecons__T5TupleTAyuTSQCgQCf__TQCaVmi32TSQCzQBu__TQBoTAQBmTQBqZQCbTQnTQCbZQDrZQCqTQBcTQCrZQEh__T4peekTQDhZQkMNgFNdZPNgAyu)
> >>>referenced by 
> >>> E:\Programs\LDC2\import\std\variant.d:753
> >>>
> >>> .dub\obj\builder.obj:(_D3std7variant__T8VariantNVmi56TSQBf8typecons__T5TupleTAyuTSQCgQCf__TQCaVmi32TSQCzQBu__TQBoTAQBmTQBqZQCbTQnTQCbZQDrZQCqTQBcTQCrZQEh__T4peekTQBwZQkMNgFNdZPNgAAyu)
> >>>   referenced by 
> >>> E:\Programs\LDC2\import\std\variant.d:820
> >>>
> >>> .dub\obj\builder.obj:(_D3std7variant__T8VariantNVmi56TSQBf8typecons__T5TupleTAyuTSQCgQCf__TQCaVmi32TSQCzQBu__TQBoTAQBmTQBqZQCbTQnTQCbZQDrZQCqTQBcTQCrZQEh__T3getTQEdZQjMNgFNdZNgSQFxQEs__TQEmTQEjTQEjZQEy)
>
> How to solve?
> This is the first time when linking fails on Phobos library.

Have you try to clean all caches? Try to remove .dub folder



Re: D for sciencetific scripting / rapid protoryping

2019-10-22 Thread Daniel Kozak via Digitalmars-d-learn
On Tue, Oct 22, 2019 at 10:25 AM Prokop Hapala via Digitalmars-d-learn
 wrote:
>
> ...
>
> Also where is RDMD in the equation? I really like the idea run
> binary programs like:
>
> #!/usr/bin/env rdmd
> import std.stdio;
> void main(){
>  writeln("Hello, world!");
> }
>
> But I cannot find any documentation how to use rdmd with any
> libraries/dependencies and dub.json ? Not even statically linked,
> not to say dynamic.
>

You can't use rdmd with dub, but for simple scripts you can use dub directly:

https://dub.pm/advanced_usage.html


Re: D for sciencetific scripting / rapid protoryping

2019-10-22 Thread Daniel Kozak via Digitalmars-d-learn
On Tue, Oct 22, 2019 at 8:00 AM Prokop Hapala via Digitalmars-d-learn
 wrote:
>
> I'm examining the possibility to move from Python+C/C++ to D or
> Python+D. I read
> (https://wiki.dlang.org/Programming_in_D_for_Python_Programmers)
> and
> (https://jackstouffer.com/blog/nd_slice.html), where is mentioned
> PyD, Mir-algorithm, all seems very promising. But I did not test
> it yet.
 >...

You should try to use https://github.com/BindBC/bindbc-opengl and
https://github.com/BindBC/bindbc-sdl. There seems to be an issue with
derelict packages (mainly with the gl3 one)
And as far as I know derelict should be replaced by bindbc anyway in future.

And if you plan to have *.so libs you should add "targetType" :
"dynamicLibrary", to you dub.json


Re: D code running on the Nintendo 3DS

2019-10-21 Thread Daniel Kozak via Digitalmars-d-announce
On Sun, Oct 20, 2019 at 11:40 PM TheGag96 via Digitalmars-d-announce
 wrote:
>
> On Sunday, 20 October 2019 at 20:31:04 UTC, Johan wrote:
> > (snip)
>
> Awesome, I just might try to get LDC working with this...
>
> ...
> ...in order to fit the D naming style, since the semantics for
> the enum was changing anyway. But of course, every struct must
> keep its old name... Is this alright? Should I add aliases for
> every struct for a better naming style, or maybe go back on my
> decision before, or...?

If it is binding you should probably let it same as original code. I
always try to make bindings as same as possible. It is much easier
port existing code in original language. If I want to change interface
or anything I made a new wrapper around that binding


Re: How can I make a program which uses all cores and 100% of cpu power?

2019-10-10 Thread Daniel Kozak via Digitalmars-d-learn
On Fri, Oct 11, 2019 at 6:58 AM Daniel Kozak  wrote:
>
>  so can stress your CPU.

can't


Re: How can I make a program which uses all cores and 100% of cpu power?

2019-10-10 Thread Daniel Kozak via Digitalmars-d-learn
On Fri, Oct 11, 2019 at 2:45 AM Murilo via Digitalmars-d-learn
 wrote:
>
> I have started working with neural networks and for that I need a
> lot of computing power but the programs I make only use around
> 30% of the cpu, or at least that is what Task Manager tells me.
> How can I make it use all 4 cores of my AMD FX-4300 and how can I
> make it use 100% of it?

You should use minimally same amount of threads as you have cores. So
in your case 4 or even more.
Than you should buy a new CPU if you really need a lot of computing
power :). Other issue can be using blocking IO, so your threads are in
idle, so can stress your CPU.


Re: D man pages

2019-10-10 Thread Daniel Kozak via Digitalmars-d-learn

On Thursday, 10 October 2019 at 19:26:36 UTC, Daniel Kozak wrote:
On Thursday, 10 October 2019 at 19:25:22 UTC, Daniel Kozak 
wrote:
On Thursday, 10 October 2019 at 19:21:06 UTC, Daniel Kozak 
wrote:
On Thursday, 10 October 2019 at 19:19:42 UTC, Daniel Kozak 
wrote:

On Thursday, 10 October 2019 at 18:52:32 UTC, Jarek wrote:
On Monday, 23 September 2019 at 12:31:16 UTC, Adam D. Ruppe 
wrote:

[...]


Hello,
thanks for reply.
This is my first dlang work:
import std.stdio;
import std.conv;
import core.sys.posix.dirent;

[...]


You should use fromStringZ: 
https://dlang.org/phobos/std_string.html#.fromStringz


stdout.writeln("Subdir: ", ent.d_name.fromStringz);



One more time :)
stdout.writeln("Subdir: ", ent.d_name.ptr.fromStringz);


and to!string works too: ent.d_name.ptr.to!string


and there is a more D idiomatic version:

import std.stdio;
import std.algorithm;
import std.file;
import std.path;

int main()
{
try
{
auto dFiles = dirEntries("/proc", SpanMode.shallow)
.filter!(f => f.isDir)
.each!((a){writefln("Subdir: %s", a.baseName);});
}
catch (FileException fe)
{
stderr.writeln(fe.msg);
return 1;
}
return 0;   
}


Re: D man pages

2019-10-10 Thread Daniel Kozak via Digitalmars-d-learn

On Thursday, 10 October 2019 at 19:21:06 UTC, Daniel Kozak wrote:
On Thursday, 10 October 2019 at 19:19:42 UTC, Daniel Kozak 
wrote:

On Thursday, 10 October 2019 at 18:52:32 UTC, Jarek wrote:
On Monday, 23 September 2019 at 12:31:16 UTC, Adam D. Ruppe 
wrote:

[...]


Hello,
thanks for reply.
This is my first dlang work:
import std.stdio;
import std.conv;
import core.sys.posix.dirent;

[...]


You should use fromStringZ: 
https://dlang.org/phobos/std_string.html#.fromStringz


stdout.writeln("Subdir: ", ent.d_name.fromStringz);



One more time :)
stdout.writeln("Subdir: ", ent.d_name.ptr.fromStringz);


Re: D man pages

2019-10-10 Thread Daniel Kozak via Digitalmars-d-learn

On Thursday, 10 October 2019 at 19:25:22 UTC, Daniel Kozak wrote:
On Thursday, 10 October 2019 at 19:21:06 UTC, Daniel Kozak 
wrote:
On Thursday, 10 October 2019 at 19:19:42 UTC, Daniel Kozak 
wrote:

On Thursday, 10 October 2019 at 18:52:32 UTC, Jarek wrote:
On Monday, 23 September 2019 at 12:31:16 UTC, Adam D. Ruppe 
wrote:

[...]


Hello,
thanks for reply.
This is my first dlang work:
import std.stdio;
import std.conv;
import core.sys.posix.dirent;

[...]


You should use fromStringZ: 
https://dlang.org/phobos/std_string.html#.fromStringz


stdout.writeln("Subdir: ", ent.d_name.fromStringz);



One more time :)
stdout.writeln("Subdir: ", ent.d_name.ptr.fromStringz);


and to!string works too: ent.d_name.ptr.to!string


Re: D man pages

2019-10-10 Thread Daniel Kozak via Digitalmars-d-learn

On Thursday, 10 October 2019 at 19:19:42 UTC, Daniel Kozak wrote:

On Thursday, 10 October 2019 at 18:52:32 UTC, Jarek wrote:
On Monday, 23 September 2019 at 12:31:16 UTC, Adam D. Ruppe 
wrote:

[...]


Hello,
thanks for reply.
This is my first dlang work:
import std.stdio;
import std.conv;
import core.sys.posix.dirent;

[...]


You should use fromStringZ: 
https://dlang.org/phobos/std_string.html#.fromStringz


stdout.writeln("Subdir: ", ent.d_name.fromStringz);


Re: D man pages

2019-10-10 Thread Daniel Kozak via Digitalmars-d-learn

On Thursday, 10 October 2019 at 18:52:32 UTC, Jarek wrote:
On Monday, 23 September 2019 at 12:31:16 UTC, Adam D. Ruppe 
wrote:

[...]


Hello,
thanks for reply.
This is my first dlang work:
import std.stdio;
import std.conv;
import core.sys.posix.dirent;

[...]


You should use fromStringZ: 
https://dlang.org/phobos/std_string.html#.fromStringz


Re: Undefined symbol: _dyld_enumerate_tlv_storage (OSX)

2019-10-10 Thread Daniel Kozak via Digitalmars-d-learn
What dmd version?

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

On Thu, Oct 10, 2019 at 8:15 PM Robert M. Münch via
Digitalmars-d-learn  wrote:
>
> I have two project I want to compile and both times get this error:
>
> Undefined symbols for architecture x86_64:
>   "_dyld_enumerate_tlv_storage", referenced from:
>   __d_dyld_getTLSRange in libphobos2.a(osx_tls.o)
>
> I'm wondering where this comes from as I didn't see it in the past. Any idea?
>
> --
> Robert M. Münch
> http://www.saphirion.com
> smarter | better | faster
>



Re: DUB mysql-native

2019-10-08 Thread Daniel Kozak via Digitalmars-d-learn

On Tuesday, 8 October 2019 at 14:19:10 UTC, Vino wrote:

On Tuesday, 8 October 2019 at 14:02:03 UTC, Vino wrote:

On Tuesday, 8 October 2019 at 11:26:24 UTC, Daniel Kozak wrote:

[...]


Hi Daniel,

   As stated I have removed those line and ran the below 
command


[...]


Hi Daniel,

  Was able to resolve the dub test issue using the you tube 
video "https://www.youtube.com/watch?v=zvrf7nlq5Og;, but not 
able to execute the code


Code Execution
cd HUB/source
app.d(3): Error: module `mysql` is in file 'mysql.d' which 
cannot be read

import path[0] = .
import path[1] = C:\D\dmd2\windows\bin\..\..\src\phobos
import path[2] = C:\D\dmd2\windows\bin\..\..\src\druntime\import
Failed: ["C:\\D\\dmd2\\windows\\bin\\dmd.exe", "-v", 
"-o-","app.d", "-I."]


From,
Vino.B


You can not use rdmd on app.d with dependencies. You have to use 
dub. I am not sure what are you trying to do, but if you are able 
to build your app with dub, than you just can run it ./hub


Re: DUB mysql-native

2019-10-08 Thread Daniel Kozak via Digitalmars-d-learn
On Tue, Oct 8, 2019 at 1:15 PM Daniel Kozak  wrote:
> ...
> It is known issue, you can not use mysql-native right now with
> anything else than libevent
>
> https://github.com/mysql-d/mysql-native/issues/199
>
> Or you can just remove
>
> "subConfigurations": {
> "vibe-d:core": "libevent"
> },
>
> from ~/.dub/packages/mysql-native-2.3.0/mysql-native/dub.json

https://github.com/mysql-d/mysql-native/commit/ec851956e579bab8d00b1ae89a5344a2babce2e3


Re: DUB mysql-native

2019-10-08 Thread Daniel Kozak via Digitalmars-d-learn
On Tue, Oct 8, 2019 at 10:55 AM Vino via Digitalmars-d-learn
 wrote:
>
> Could not resolve configuration for package hub
>
> From,
> Vino.B

It is known issue, you can not use mysql-native right now with
anything else than libevent

https://github.com/mysql-d/mysql-native/issues/199

Or you can just remove

"subConfigurations": {
"vibe-d:core": "libevent"
},

from ~/.dub/packages/mysql-native-2.3.0/mysql-native/dub.json


Re: must scope for delegates restrict compilation?

2019-10-03 Thread Daniel Kozak via Digitalmars-d-learn
On Thu, Oct 3, 2019 at 2:00 PM Oleg B via Digitalmars-d-learn
 wrote:
>
> Hello all
>
> I think this code must get compilation error, but it didn't,
> furthermore result program get UB.
>
> https://run.dlang.io/is/Qpr278
>
> Is this correct behavior and why?

when you change it a litle it seems works ok:

import std.stdio;
struct Foo
{
int delegate() dg;
void foo(return scope int delegate() dg)
{
this.dg = dg;
}
int call() { return dg(); }
}

Foo getFoo()
{
int x = 42;
Foo ret;
ret.foo(() => x);
return ret;
}

void main()
{
writeln(getFoo().call());
}


Re: Why is the fPIC switch missing?

2019-09-23 Thread Daniel Kozak via Digitalmars-d-learn
On Mon, Sep 23, 2019 at 3:35 AM Emmanuelle via Digitalmars-d-learn
 wrote:
>
> Forgot to say: dmd v2.088.0. Also, weirdly enough, `dmd
> --version` outputs `DMD32 D Compiler v2.088.0-dirty`. Why is
> "dirty" there?

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


Re: Why is the fPIC switch missing?

2019-09-23 Thread Daniel Kozak via Digitalmars-d-learn
On Mon, Sep 23, 2019 at 3:35 AM Emmanuelle via Digitalmars-d-learn
 wrote:
>
> Hello. My problem is exactly what it says on the title: my dmd
> (windows 7, x64) doesn't seem to have -fPIC:
>
> ---
> > dmd -fPIC
> Error: unrecognized switch '-fPIC'
> run `dmd` to print the compiler manual
> run `dmd -man` to open browser on manual
> ---
>
> `dmd --help` also doesn't have anything about fPIC. Sorry if I'm
> being dense but why is that? Is it only available on Linux?
>
> Thank you!

It seems it is not available for windows and MacOS:

https://github.com/dlang/dmd/blob/639c67162b2be90ebf8dc9a9f8118cb2a9606569/src/dmd/cli.d#L323


Re: The biggest issue in Dlang

2019-09-19 Thread Daniel Kozak via Digitalmars-d-learn
On Thursday, 19 September 2019 at 20:50:30 UTC, Daniel Kozak 
wrote:

auto main()
{
return int(0);
}

for some reasons does not work WOW :-D

this works ok:
void main()
{
return other();
}

auto other()
{
return;
}

so I believe even this should work:

auto main()
{
return;
}


I am aware of https://dlang.org/spec/function.html#main, just 
seems wierd auto does not work too


The biggest issue in Dlang

2019-09-19 Thread Daniel Kozak via Digitalmars-d-learn

auto main()
{
return int(0);
}

for some reasons does not work WOW :-D

this works ok:
void main()
{
return other();
}

auto other()
{
return;
}

so I believe even this should work:

auto main()
{
return;
}




Re: Problem with using std.math: abs and std.complex: abs at the same time

2019-09-18 Thread Daniel Kozak via Digitalmars-d-learn
On Wed, Sep 18, 2019 at 2:05 PM berni via Digitalmars-d-learn
 wrote:
>
> The following code doesn't compile:
>
> >import std.stdio;
> >
> >void main()
> >{
> >import std.complex: abs, complex;
> >import std.math: abs;
> >
> >auto a = complex(1.0,1.0);
> >auto b = 1.0;
> >
> >writeln(abs(a));
> >writeln(abs(b));
> >}
>
> The error message depends on the order of the two import
> statements. Seems like the second import is actually ignored.
>
> I hoped for a mechanism similar to overloading, which makes the
> compiler decide, which "abs" to use, depending on the type of the
> operand. Is there a way to do this? (As the code appears inside a
> template, something like std.math.abs() with static import
> doesn't work out well.)

import std.stdio;

void main()
{
import std.complex: abs, complex;
import std.math: mabs = abs;

auto a = complex(1.0,1.0);
auto b = 1.0;

writeln(abs(a));
writeln(mabs(b));
}


DUB WTF?

2019-09-18 Thread Daniel Kozak via Digitalmars-d-learn
Why is dub automaticaly changing dub.sdl from packages to 
dub.json?


Re: getting rid of immutable (or const)

2019-09-05 Thread Daniel Kozak via Digitalmars-d-learn
On Thu, Sep 5, 2019 at 9:55 AM berni via Digitalmars-d-learn
 wrote:
>
> I still struggle with the concept of immutable and const:
>
> > import std.stdio;
> >
> > void main()
> > {
> > auto p = Point(3);
> > auto q = p.x;
> > writeln(typeof(q).stringof);
> > }
> >
> > struct Point
> > {
> > @property immutable long x;
> > }
>
> The type of q is immutable(long). But I need a mutable q. I found
> two ways:
>
> a) long q = p.x;
> b) auto q = cast(long)p.x;
>
> Either way I've to specify the type "long" which I dislike (here
> it's not a real burdon, but with more complicated types it might
> be). Is there a way, to make q mutable without having to write
> the type explicitly?

in this case you can just use:

auto q = cast()p.x;


Re: Release D 2.088.0

2019-09-03 Thread Daniel Kozak via Digitalmars-d-announce
On Tue, Sep 3, 2019 at 10:48 AM Manu via Digitalmars-d-announce
 wrote:
>
> On Tue., 3 Sep. 2019, 1:00 am Martin Nowak via Digitalmars-d-announce, 
>  wrote:
>>
>> Glad to announce D 2.088.0, ♥ to the 58 contributors.
>>
>> This release comes with a new getLocation trait, a getAvailableDiskSpace
>> in std.file, removal and deprecation of lots of various outdated APIs,
>> an core.atomic.cas with result value, and a couple of more changes.
>>
>> http://dlang.org/download.html
>> http://dlang.org/changelog/2.088.0.html
>>
>> -Martin
>
>
> Huzzah!
>
> I like to think std::string and std::vector are a pretty big deal too ;)

It will be as soon as gcc with new ABI will be supported ;-)



Re: What is "dmd" Internal API, can I use it just like std Library Reference?

2019-08-20 Thread Daniel Kozak via Digitalmars-d-learn
On Tue, Aug 20, 2019 at 2:55 PM BoQsc via Digitalmars-d-learn
 wrote:
>
> Hello everyone, again,
>
> I had an idea that I want some colors in the output of Command
> Line (For Windows) and
> the Terminal (For Linux)
>
> I found https://dlang.org/phobos/dmd_console.html and wanted to
> use it.
> But it seems I'm not being successful, and I do not understand
> why.
>
> Here, you can see that I'm trying to import dmd.console;
>
> > import std.stdio : writeln;
> > import dmd.console;
> >
> > void main()
> > {
> > writeln("Hello World");
> > }
>
> And the output says that, dmd.console; do not exist?
> What are these Internal APIs for?
> > C:\Users\Juozas\Desktop>rdmd color.d
> > color.d(2): Error: module `console` is in file 'dmd\console.d'
> > which cannot be read

It is internal and it is part of dmd compiler sources but it is not
supposed to be used in normal D code. If you want colors in console
you can try this:
https://github.com/Kripth/terminal

you can use it as a dup dependency or just add terminal.d to your code base


Re: Downloading a file and showing progress via curl.

2019-08-20 Thread Daniel Kozak via Digitalmars-d-learn
On Tue, Aug 20, 2019 at 1:40 PM BoQsc via Digitalmars-d-learn
 wrote:
>
> Hello everyone,
> I found this snippet on
> https://dlang.org/phobos/std_net_curl.html#.HTTP
>
> > import std.net.curl : HTTP;
> > import std.stdio : writeln;
> >
> > void main()
> > {
> > auto http = HTTP();
> > // Track progress
> > http.method = HTTP.Method.get;
> > http.url =
> > "https://upload.wikimedia.org/wikipedia/commons/5/53/Wikipedia-logo-en-big.png;;
> > http.onReceive = (ubyte[] data) { return data.length; };
> > http.onProgress = (size_t dltotal, size_t dlnow, size_t
> > ultotal, size_t ulnow) {
> > writeln("Progress ", dltotal, ", ", dlnow, ", ",
> > ultotal, ", ", ulnow);
> > return 0;
> > };
> > http.perform();
> > }
>
> This snippet is showing Download Progress in bytes, but I'm
> unsure how to save the
> downloaded file into filesystem after download is completed.

You just need to save data in onReceive callback


Re: Downloading a file and showing progress via curl.

2019-08-20 Thread Daniel Kozak via Digitalmars-d-learn
On Tue, Aug 20, 2019 at 1:46 PM Daniel Kozak  wrote:
>
> On Tue, Aug 20, 2019 at 1:40 PM BoQsc via Digitalmars-d-learn
>  wrote:
> >
> > Hello everyone,
> > I found this snippet on
> > https://dlang.org/phobos/std_net_curl.html#.HTTP
> >
> > > import std.net.curl : HTTP;
> > > import std.stdio : writeln;
> > >
> > > void main()
> > > {
> > > auto http = HTTP();
> > > // Track progress
> > > http.method = HTTP.Method.get;
> > > http.url =
> > > "https://upload.wikimedia.org/wikipedia/commons/5/53/Wikipedia-logo-en-big.png;;
> > > http.onReceive = (ubyte[] data) { return data.length; };
> > > http.onProgress = (size_t dltotal, size_t dlnow, size_t
> > > ultotal, size_t ulnow) {
> > > writeln("Progress ", dltotal, ", ", dlnow, ", ",
> > > ultotal, ", ", ulnow);
> > > return 0;
> > > };
> > > http.perform();
> > > }
> >
> > This snippet is showing Download Progress in bytes, but I'm
> > unsure how to save the
> > downloaded file into filesystem after download is completed.
>
> You just need to save data in onReceive callback

For that you can use https://dlang.org/phobos/std_file#append


Re: Can't add a const ubyte to a dynamic array of ubyte?

2019-08-20 Thread Daniel Kozak via Digitalmars-d-learn
On Tue, Aug 20, 2019 at 11:30 AM ads via Digitalmars-d-learn
 wrote:
>
>
> How can I get around this? I want to ensure that the array is not
> mutated in the function in the signature too.
>

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

import std.stdio;

ubyte[] extend(in uint[] arr)
{
ubyte[] result;
foreach (n; arr)
{
if (n < 10)
{
result ~= cast(ubyte)n;
// source/app.d(10,11): Error: cannot append type
const(uint) to type ubyte[]
}
else
{
import std.conv : to;

foreach (digit; n.to!string)
{
result ~= cast(ubyte)(digit - '0');
}
}
}
return result;
}

unittest
{
import std.algorithm : equal;
assert(extend([1, 25, 70, 0]).equal([1, 2, 5, 7, 0, 0]));
}


Re: How to use #pragma omp parallel for collapse(n) in dlang?

2019-08-15 Thread Daniel Kozak via Digitalmars-d-learn
On Thu, Aug 15, 2019 at 9:44 AM Daniel Kozak  wrote:
>
> On Tue, Aug 13, 2019 at 10:47 AM ijet via Digitalmars-d-learn
>  wrote:
> >
> > How to use #pragma omp parallel for collapse(n) in dlang?
>
> There is no OMP for de as I know, but you can just use
> https://dlang.org/phobos/std_parallelism.html#.parallel
> for each 'foreach'

something like this:
C version:

#include 
#define CNT 40

int isprime(int num)
{
 if (num <= 1) return 0;
 if (num % 2 == 0 && num > 2) return 0;
 for(int i = 3; i < num / 2; i+= 2)
 {
 if (num % i == 0)
 return 0;
 }
 return 1;
}


int fun(int a, int b)
{
return isprime(a) + isprime(b);
}

int main() {
int buff[CNT];
int i, j;
#pragma omp parallel for private(j) collapse(2)
for (i = 0; i < 4; i++)
for (j = 0; j < 10; j++)
buff[i*10 + j] = fun(i, j);

for (int x = 0; x < CNT; x++)
{
printf("%d\n", buff[x]);
}
return 0;
}

D version:

import core.stdc.stdio;
import std.parallelism;
import std.range : iota;

enum CNT = 40;

int isprime(int num)
{
 if (num <= 1) return 0;
 if (num % 2 == 0 && num > 2) return 0;
 for(int i = 3; i < num / 2; i+= 2)
 {
 if (num % i == 0)
 return 0;
 }
 return 1;
}


int fun(int a, int b)
{
return isprime(a) + isprime(b);
}

int main(string[] args)
{
int[CNT] buff = void;

foreach (i; iota(0,4).parallel)
foreach (j; iota(0, 10).parallel)
buff[i*10 + j] = fun(i, j);

for (int x = 0; x < CNT; x++)
{
printf("%d\n", buff[x]);
}
return 0;
}


Re: How to use #pragma omp parallel for collapse(n) in dlang?

2019-08-15 Thread Daniel Kozak via Digitalmars-d-learn
On Tue, Aug 13, 2019 at 10:47 AM ijet via Digitalmars-d-learn
 wrote:
>
> How to use #pragma omp parallel for collapse(n) in dlang?

There is no OMP for de as I know, but you can just use
https://dlang.org/phobos/std_parallelism.html#.parallel
for each 'foreach'


  1   2   3   4   5   6   7   8   9   >