Re: short guide on getting started with D

2023-04-04 Thread thinkunix via Digitalmars-d-learn
cgenie via Digitalmars-d-learn wrote: Hello, I created a short guide on getting started with D: https://blog.mmksoft.uk/#A%20short%20guide%20on%20getting%20started%20with%20D%20programming This is because I recently I started to explore the language and, having read the forum, I see DUB

Re: foreach (i; taskPool.parallel(0..2_000_000)

2023-04-04 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Apr 04, 2023 at 09:35:29PM +, Paul via Digitalmars-d-learn wrote: [...] > Well Steven just making the change you said reduced the execution time > from ~6-7 secs to ~3 secs. Then, including the 'parallel' in the > foreach statement took it down to ~1 sec. > > Boy lesson learned in

Re: Virtual method call from constructor

2023-04-04 Thread Ali Çehreli via Digitalmars-d-learn
On 4/4/23 00:08, Chris Katko wrote: > dscanner reports this as a warning: > > ```D > struct foo{ > this() >{ >/* some initial setup */ >refresh(); >} > void refresh() { /* setup some more stuff */} > // [warn] a virtual call inside a constructor may lead to unexpected > results in

Re: foreach (i; taskPool.parallel(0..2_000_000)

2023-04-04 Thread Paul via Digitalmars-d-learn
On Monday, 3 April 2023 at 23:50:48 UTC, Steven Schveighoffer wrote: So what you need is inside `createSpansOfNoBeacons`, take as a reference a `ref Span[MAX_SPANS]`, and have it return a `Span[]` that is a slice of that which was "alocated". See if this helps. Well Steven just making the

How do you work with unittest libraries in dub packages?

2023-04-04 Thread Christian Köstlin via Digitalmars-d-learn
Recently Dmytro Katyukha brought up an issue in one of my dub packages that is supposed to be used as a library. He even went the whole way and came up with a simple reduced example: https://gitlab.com/gizmomogwai/colored/-/merge_requests/3#note_1341026928. The problem here is, that my dub

Re: foreach (i; taskPool.parallel(0..2_000_000)

2023-04-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/4/23 11:34 AM, Salih Dincer wrote: On Tuesday, 4 April 2023 at 14:20:20 UTC, Steven Schveighoffer wrote: parallel is a shortcut to `TaskPool.parallel`, which is indeed a foreach-only construct, it does not return a range. I think what you want is `TaskPool.map`: ```d // untested, just

Re: foreach (i; taskPool.parallel(0..2_000_000)

2023-04-04 Thread Salih Dincer via Digitalmars-d-learn
On Tuesday, 4 April 2023 at 14:20:20 UTC, Steven Schveighoffer wrote: parallel is a shortcut to `TaskPool.parallel`, which is indeed a foreach-only construct, it does not return a range. I think what you want is `TaskPool.map`: ```d // untested, just looking at the taskPool.map!(/* your map

Re: foreach (i; taskPool.parallel(0..2_000_000)

2023-04-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/4/23 5:24 AM, Salih Dincer wrote: Is it necessary to enclose the code in `foreach()`? I invite Ali to tell me! Please explain why parallel isn't running. parallel is a shortcut to `TaskPool.parallel`, which is indeed a foreach-only construct, it does not return a range. I think what

Re: foreach (i; taskPool.parallel(0..2_000_000)

2023-04-04 Thread Ali Çehreli via Digitalmars-d-learn
On 4/4/23 02:24, Salih Dincer wrote: > I don't understand what `foreach()` does :) Hm. I forgot whether 'parallel' works only with 'foreach'. But there are various other algorithms in std.parallelism that may be more useful with range algorithm chains:

Re: What do you think about using Chat GPT to create functions in D?

2023-04-04 Thread Guillaume Piolat via Digitalmars-d-learn
On Monday, 3 April 2023 at 23:38:52 UTC, Marcone wrote: What do you think about using Chat GPT to create functions in D? Well you can use GitHub Copilot in VSCode, and it is kind of interesting but at the current time seems like a distracting waste of time. It will probably get more useful

Re: foreach (i; taskPool.parallel(0..2_000_000)

2023-04-04 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 3 April 2023 at 22:24:18 UTC, Steven Schveighoffer wrote: So for example, if you have: ```d foreach(i; iota(0, 2_000_000).parallel) { runExpensiveTask(i); } ``` The foreach is run on the main thread, gets a `0`, then hands off to a task thread `runExpensiveTask(0)`. Then it gets

Re: Virtual method call from constructor

2023-04-04 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
> Firstly, are all calls virtual in a struct/class in D? In D structs are always value types without a vtable or inheritance. Classes are always reference types with a vtable, but some of the methods may be final and hence not in vtable. > Second, could you give me some case examples where

Virtual method call from constructor

2023-04-04 Thread Chris Katko via Digitalmars-d-learn
dscanner reports this as a warning: ```D struct foo{ this() { /* some initial setup */ refresh(); } void refresh() { /* setup some more stuff */} // [warn] a virtual call inside a constructor may lead to unexpected results in the derived classes } ``` Firstly, are all calls virtual