Re: Reduce parameters [was pi program]

2015-09-26 Thread Russel Winder via Digitalmars-d-learn
On Fri, 2015-09-25 at 12:54 +, John Colvin via Digitalmars-d-learn wrote: > […] > I vastly prefer the UFCS version, but unfortunately reduce has > its arguments the wrong way around for that if you use the > version that takes a seed... In which case the reduce parameter list is wrong,

Re: Parallel processing and further use of output

2015-09-26 Thread Zoidberg via Digitalmars-d-learn
Here's a correct version: import std.parallelism, std.range, std.stdio, core.atomic; void main() { shared ulong i = 0; foreach (f; parallel(iota(1, 100+1))) { i.atomicOp!"+="(f); } i.writeln; } Thanks! Works fine. So "shared" and "atomic" is a must?

Re: Parallel processing and further use of output

2015-09-26 Thread John Colvin via Digitalmars-d-learn
On Saturday, 26 September 2015 at 12:18:16 UTC, Zoidberg wrote: I've run into an issue, which I guess could be resolved easily, if I knew how... [CODE] ulong i = 0; foreach (f; parallel(iota(1, 100+1))) { i += f; } thread_joinAll(); i.writeln; [/CODE] It's

Re: Threading Questions

2015-09-26 Thread ponce via Digitalmars-d-learn
Sorry I don't know the answers but these questions are interesting so BUMP ;) On Friday, 25 September 2015 at 15:19:27 UTC, bitwise wrote: 1) Are the following two snippets exactly equivalent(not just in observable behaviour)? a) Mutex mut; mut.lock(); scope(exit) mut.unlock(); b) Mutex

Why getting private member fails using getMember trait in a template?

2015-09-26 Thread Alexandru Ermicioi via Digitalmars-d-learn
Suppose we have, two modules: module testOne; import std.traits; template getMember(alias T, string member) { alias getMember = Identity!(__traits(getMember, T, member)); } module app; import testOne; import std.traits; class TestOne { private { int property; }

Re: Mac IDE with Intellisense

2015-09-26 Thread Gary Willoughby via Digitalmars-d-learn
On Saturday, 26 September 2015 at 09:17:10 UTC, Mike McKee wrote: I was doing toHexString(myByteArray) instead of simply doing myByteArray.toHexString(). (That was on an md5 example, by the way.) Intellisense would have helped me realize this. Both these forms are the same. It's called UFCS

Re: Mac IDE with Intellisense

2015-09-26 Thread Rikki Cattermole via Digitalmars-d-learn
On 26/09/15 9:17 PM, Mike McKee wrote: I've tried Sublime Text 3 editor on the Mac, but even it doesn't seem to have the D2 language in it yet (only D), and doesn't have intellisense for components in the imports that I do, even after saving the file after adding the import statements. What OSX

Re: Parallel processing and further use of output

2015-09-26 Thread Meta via Digitalmars-d-learn
On Saturday, 26 September 2015 at 12:33:45 UTC, anonymous wrote: foreach (f; parallel(iota(1, 100+1))) { synchronized i += f; } Is this valid syntax? I've never seen synchronized used like this before.

Mac IDE with Intellisense

2015-09-26 Thread Mike McKee via Digitalmars-d-learn
I've tried Sublime Text 3 editor on the Mac, but even it doesn't seem to have the D2 language in it yet (only D), and doesn't have intellisense for components in the imports that I do, even after saving the file after adding the import statements. What OSX editor do you recommend that would

Re: Mac IDE with Intellisense

2015-09-26 Thread wobbles via Digitalmars-d-learn
On Saturday, 26 September 2015 at 09:17:10 UTC, Mike McKee wrote: I've tried Sublime Text 3 editor on the Mac, but even it doesn't seem to have the D2 language in it yet (only D), and doesn't have intellisense for components in the imports that I do, even after saving the file after adding the

Re: Parallel processing and further use of output

2015-09-26 Thread anonymous via Digitalmars-d-learn
On Saturday 26 September 2015 14:18, Zoidberg wrote: > I've run into an issue, which I guess could be resolved easily, > if I knew how... > > [CODE] > ulong i = 0; > foreach (f; parallel(iota(1, 100+1))) > { > i += f; > } > thread_joinAll(); >

Parallel processing and further use of output

2015-09-26 Thread Zoidberg via Digitalmars-d-learn
I've run into an issue, which I guess could be resolved easily, if I knew how... [CODE] ulong i = 0; foreach (f; parallel(iota(1, 100+1))) { i += f; } thread_joinAll(); i.writeln; [/CODE] It's basically an example which adds all the numbers from 1 to

Re: Reduce parameters [was pi program]

2015-09-26 Thread John Colvin via Digitalmars-d-learn
On Saturday, 26 September 2015 at 06:28:22 UTC, Russel Winder wrote: On Fri, 2015-09-25 at 12:54 +, John Colvin via Digitalmars-d-learn wrote: […] I vastly prefer the UFCS version, but unfortunately reduce has its arguments the wrong way around for that if you use the version that takes

Re: Parallel processing and further use of output

2015-09-26 Thread anonymous via Digitalmars-d-learn
On Saturday, 26 September 2015 at 13:09:54 UTC, Meta wrote: On Saturday, 26 September 2015 at 12:33:45 UTC, anonymous wrote: foreach (f; parallel(iota(1, 100+1))) { synchronized i += f; } Is this valid syntax? I've never seen synchronized used like this before. I'm

Re: Mac IDE with Intellisense

2015-09-26 Thread Mike McKee via Digitalmars-d-learn
On Saturday, 26 September 2015 at 10:31:13 UTC, wobbles wrote: Have you installed dkit for sublime? As in? https://github.com/yazd/DKit Looks like it's alpha and doesn't run on Mac? No homebrew install?

Re: Purity of std.conv.to!string

2015-09-26 Thread Xinok via Digitalmars-d-learn
On Saturday, 26 September 2015 at 17:08:00 UTC, Nordlöw wrote: Why is the following code not pure: float x = 3.14; import std.conv : to; auto y = x.to!string; ??? Is there a reason for it not being pure? If not, this is a serious problem as this is such a fundamental function.

Re: Parallel processing and further use of output

2015-09-26 Thread Jay Norwood via Digitalmars-d-learn
btw, on my corei5, in debug build, reduce (using double): 11msec non_parallel: 37msec parallel with atomicOp: 123msec so, that is the reason for using parallel reduce, assuming the ulong range thing will get fixed.

Re: Mac IDE with Intellisense

2015-09-26 Thread Mike McKee via Digitalmars-d-learn
On Saturday, 26 September 2015 at 10:38:29 UTC, Gary Willoughby wrote: Both these forms are the same. It's called UFCS (uniform function call syntax). Here's some material to help you understand what's going on here: http://ddili.org/ders/d.en/ufcs.html

Re: Purity of std.conv.to!string

2015-09-26 Thread cym13 via Digitalmars-d-learn
On Saturday, 26 September 2015 at 17:08:00 UTC, Nordlöw wrote: Why is the following code not pure: float x = 3.14; import std.conv : to; auto y = x.to!string; ??? Is there a reason for it not being pure? If not, this is a serious problem as this is such a fundamental function.

Purity of std.conv.to!string

2015-09-26 Thread Nordlöw via Digitalmars-d-learn
Why is the following code not pure: float x = 3.14; import std.conv : to; auto y = x.to!string; ??? Is there a reason for it not being pure? If not, this is a serious problem as this is such a fundamental function.

Re: Parallel processing and further use of output

2015-09-26 Thread Jay Norwood via Digitalmars-d-learn
This is a work-around to get a ulong result without having the ulong as the range variable. ulong getTerm(int i) { return i; } auto sum4 = taskPool.reduce!"a + b"(std.algorithm.map!getTerm(iota(11)));

Re: Parallel processing and further use of output

2015-09-26 Thread John Colvin via Digitalmars-d-learn
On Saturday, 26 September 2015 at 17:20:34 UTC, Jay Norwood wrote: This is a work-around to get a ulong result without having the ulong as the range variable. ulong getTerm(int i) { return i; } auto sum4 = taskPool.reduce!"a + b"(std.algorithm.map!getTerm(iota(11))); or auto

Re: Parallel processing and further use of output

2015-09-26 Thread Jay Norwood via Digitalmars-d-learn
std.parallelism.reduce documentation provides an example of a parallel sum. This works: auto sum3 = taskPool.reduce!"a + b"(iota(1.0,101.0)); This results in a compile error: auto sum3 = taskPool.reduce!"a + b"(iota(1UL,101UL)); I believe there was discussion of this problem recently

Re: Parallel processing and further use of output

2015-09-26 Thread Zoidberg via Digitalmars-d-learn
On Saturday, 26 September 2015 at 13:09:54 UTC, Meta wrote: On Saturday, 26 September 2015 at 12:33:45 UTC, anonymous wrote: foreach (f; parallel(iota(1, 100+1))) { synchronized i += f; } Is this valid syntax? I've never seen synchronized used like this before.

Re: Purity of std.conv.to!string

2015-09-26 Thread Jack Stouffer via Digitalmars-d-learn
On Saturday, 26 September 2015 at 17:08:00 UTC, Nordlöw wrote: Why is the following code not pure: float x = 3.14; import std.conv : to; auto y = x.to!string; ??? Is there a reason for it not being pure? If not, this is a serious problem as this is such a fundamental function.

Re: Mac IDE with Intellisense

2015-09-26 Thread extrawurst via Digitalmars-d-learn
On Saturday, 26 September 2015 at 09:17:10 UTC, Mike McKee wrote: I've tried Sublime Text 3 editor on the Mac, but even it doesn't seem to have the D2 language in it yet (only D), and doesn't have intellisense for components in the imports that I do, even after saving the file after adding the