Re: How to work around the infamous dual-context when using delegates together with std.parallelism

2021-05-31 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/31/21 12:50 PM, Christian Köstlin wrote: On 2021-05-31 13:40, CandG wrote: On Thursday, 27 May 2021 at 14:44:29 UTC, Steven Schveighoffer wrote: On 5/27/21 10:13 AM, Christian Köstlin wrote: P.S.: I still do not get how to post formatted snippets with thunderbird to the newsgroup/forum :/

Re: How to work around the infamous dual-context when using delegates together with std.parallelism

2021-05-31 Thread Christian Köstlin via Digitalmars-d-learn
On 2021-05-31 18:50, Christian Köstlin wrote: On 2021-05-31 13:40, CandG wrote: On Thursday, 27 May 2021 at 14:44:29 UTC, Steven Schveighoffer wrote: On 5/27/21 10:13 AM, Christian Köstlin wrote: P.S.: I still do not get how to post formatted snippets with thunderbird to the newsgroup/forum :/

Re: How to work around the infamous dual-context when using delegates together with std.parallelism

2021-05-31 Thread Christian Köstlin via Digitalmars-d-learn
On 2021-05-31 13:40, CandG wrote: On Thursday, 27 May 2021 at 14:44:29 UTC, Steven Schveighoffer wrote: On 5/27/21 10:13 AM, Christian Köstlin wrote: P.S.: I still do not get how to post formatted snippets with thunderbird to the newsgroup/forum :/ It's not possible currently. I no longer u

Re: How to work around the infamous dual-context when using delegates together with std.parallelism

2021-05-31 Thread CandG via Digitalmars-d-learn
On Thursday, 27 May 2021 at 14:44:29 UTC, Steven Schveighoffer wrote: On 5/27/21 10:13 AM, Christian Köstlin wrote: P.S.: I still do not get how to post formatted snippets with thunderbird to the newsgroup/forum :/ It's not possible currently. I no longer use thunderbird, but: - https://gi

Re: How to work around the infamous dual-context when using delegates together with std.parallelism

2021-05-27 Thread Christian Köstlin via Digitalmars-d-learn
On 2021-05-27 18:56, Ali Çehreli wrote: On 5/27/21 9:19 AM, Ali Çehreli wrote:    auto result = new string[users.length];    users.enumerate.parallel.each!(en => result[en.index] = servers.doSomething(en.value));    writeln(result); I still like the foreach version more:     auto result =

Re: How to work around the infamous dual-context when using delegates together with std.parallelism

2021-05-27 Thread Ali Çehreli via Digitalmars-d-learn
On 5/27/21 9:19 AM, Ali Çehreli wrote:   auto result = new string[users.length];   users.enumerate.parallel.each!(en => result[en.index] = servers.doSomething(en.value));   writeln(result); I still like the foreach version more: auto result = new string[users.length]; foreach (i,

Re: How to work around the infamous dual-context when using delegates together with std.parallelism

2021-05-27 Thread Ali Çehreli via Digitalmars-d-learn
On 5/27/21 2:58 AM, Christian Köstlin wrote: > writeln(taskPool.amap!(user => servers.doSomething(user))(users)); Luckily, parallel() is a free-standing function that does not require a "this context". Is the following a workaround for you? auto result = new string[users.length]; use

Re: How to work around the infamous dual-context when using delegates together with std.parallelism

2021-05-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/27/21 10:13 AM, Christian Köstlin wrote: P.S.: I still do not get how to post formatted snippets with thunderbird to the newsgroup/forum :/ It's not possible currently. I keep posting all my thunderbird posts *as if* the forum will highlight them in the hopes that some day it will retroa

Re: How to work around the infamous dual-context when using delegates together with std.parallelism

2021-05-27 Thread Christian Köstlin via Digitalmars-d-learn
On 2021-05-27 15:00, sighoya wrote: On Thursday, 27 May 2021 at 12:58:28 UTC, Christian Köstlin wrote: That looks nice, but unfortunately my data for servers and users in the real world is not static but comes from a config file. Okay, but then parametrizing the static lambda with runtime par

Re: How to work around the infamous dual-context when using delegates together with std.parallelism

2021-05-27 Thread sighoya via Digitalmars-d-learn
On Thursday, 27 May 2021 at 12:58:28 UTC, Christian Köstlin wrote: That looks nice, but unfortunately my data for servers and users in the real world is not static but comes from a config file. Okay, but then parametrizing the static lambda with runtime parameters should work. The important

Re: How to work around the infamous dual-context when using delegates together with std.parallelism

2021-05-27 Thread Christian Köstlin via Digitalmars-d-learn
On 2021-05-27 14:48, sighoya wrote: On Thursday, 27 May 2021 at 12:17:36 UTC, Christian Köstlin wrote: Can you explain me, where here a double context is needed? Because all data now should be passed as arguments to amap? Kind regards, Christian I  believe D's type system isn't smart enough

Re: How to work around the infamous dual-context when using delegates together with std.parallelism

2021-05-27 Thread sighoya via Digitalmars-d-learn
On Thursday, 27 May 2021 at 12:17:36 UTC, Christian Köstlin wrote: Can you explain me, where here a double context is needed? Because all data now should be passed as arguments to amap? Kind regards, Christian I believe D's type system isn't smart enough to see independence between context

Re: How to work around the infamous dual-context when using delegates together with std.parallelism

2021-05-27 Thread Christian Köstlin via Digitalmars-d-learn
On 2021-05-27 13:11, sighoya wrote: On Thursday, 27 May 2021 at 09:58:40 UTC, Christian Köstlin wrote: I have this small program here test.d: ``` import std; string doSomething(string[] servers, string user) {     return user ~ servers[0]; } void main() {     auto servers = ["s1", "s2", "s3"];

Re: How to work around the infamous dual-context when using delegates together with std.parallelism

2021-05-27 Thread Christian Köstlin via Digitalmars-d-learn
Thanks for the proposed solution. It also works in my slightly bigger program (although I do not like to make servers more global). I tried also the following (which unfortunately also does not work as intended): ```D import std; string doSomething(string[] servers, string user) { return

Re: How to work around the infamous dual-context when using delegates together with std.parallelism

2021-05-27 Thread sighoya via Digitalmars-d-learn
On Thursday, 27 May 2021 at 09:58:40 UTC, Christian Köstlin wrote: I have this small program here test.d: ``` import std; string doSomething(string[] servers, string user) { return user ~ servers[0]; } void main() { auto servers = ["s1", "s2", "s3"]; auto users = ["u1", "u2", "u3"];

How to work around the infamous dual-context when using delegates together with std.parallelism

2021-05-27 Thread Christian Köstlin via Digitalmars-d-learn
I have this small program here test.d: ``` import std; string doSomething(string[] servers, string user) { return user ~ servers[0]; } void main() { auto servers = ["s1", "s2", "s3"]; auto users = ["u1", "u2", "u3"]; writeln(map!(user => servers.doSomething(user))(users)); wri