Re: Lambda functions in D

2015-05-09 Thread Timon Gehr via Digitalmars-d-learn
On 05/09/2015 05:52 PM, Dennis Ritchie wrote: On Saturday, 9 May 2015 at 14:15:21 UTC, Ali Çehreli wrote: On 05/09/2015 04:59 AM, Dennis Ritchie wrote: On Saturday, 9 May 2015 at 11:49:48 UTC, Timon Gehr wrote: assert((function int(int x)=x?x*__traits(parent,{})(x-1):1)(10)==3628800);

Re: How to translate this to D: const char *const* someConstPtr;

2015-05-09 Thread Adam D. Ruppe via Digitalmars-d-learn
The second const isn't needed in D, the first one will carry through for it too. const char* in D is equivalent to that C declaration. const(char)* in D is what const char* in C would be.

Re: Spawning a console in Windows (similar to forkpty on linux)

2015-05-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 9 May 2015 at 13:00:01 UTC, wobbles wrote: On Linux, I'm able to edit a file descriptor after I've created it to tell it to read/write asynchronously, I cant seem to find anything similar on windows however. Asynchronous I/O on Windows is called Overlapped I/O. It is a bit

Re: how does 'shared' affect member variables?

2015-05-09 Thread bitwise via Digitalmars-d-learn
On Sat, 09 May 2015 21:32:42 -0400, Mike n...@none.com wrote: it looks like what you are trying to implement is what `synchronized` already provides: http://ddili.org/ders/d.en/concurrency_shared.html#ix_concurrency_shared.synchronized Mike Yes, but synchronized uses a mutex. Spin locks

Re: Spawning a console in Windows (similar to forkpty on linux)

2015-05-09 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 9 May 2015 at 18:19:16 UTC, Baz wrote: You need a loop that run until the PID is invalid. You could also call WaitForSingleObject on the process handle https://msdn.microsoft.com/en-us/library/windows/desktop/ms687032%28v=vs.85%29.aspx The HANDLE it expects can be gotten from

Re: How to translate this to D: const char *const* someConstPtr;

2015-05-09 Thread Ali Çehreli via Digitalmars-d-learn
On 05/09/2015 04:18 PM, ParticlePeter wrote: const char *const* someConstPtr; Disecting: 1) const char : There are these chars that cannot be modified 2) * : There are these pointers to such const chars. 3) const: Those pointers cannot point to anything else 4) * : There are these pointers

Re: how does 'shared' affect member variables?

2015-05-09 Thread bitwise via Digitalmars-d-learn
On Sat, 09 May 2015 15:38:05 -0400, Mike n...@none.com wrote: On Saturday, 9 May 2015 at 18:41:59 UTC, bitwise wrote: Also, I wasn't able to find any thorough documentation on shared, so if someone has a link, that would be helpful. Here are a few interesting links: Iain Buclaw (lead

Re: how does 'shared' affect member variables?

2015-05-09 Thread anonymous via Digitalmars-d-learn
On Saturday, 9 May 2015 at 18:41:59 UTC, bitwise wrote: What does 'shared' do to member variables? Makes them `shared`. :P It makes sense to me to put it on a global variable, but what sense does it make putting it on a member of a class? Globals are not the only way to pass data to other

Re: how does 'shared' affect member variables?

2015-05-09 Thread anonymous via Digitalmars-d-learn
On Saturday, 9 May 2015 at 19:59:58 UTC, tcak wrote: Stupidly, shared variables' value cannot be increased/decreased directly. Compiler says it is deprecated, and tells me to use core.atomic.atomicop. You will see this as well. How's that stupid? Sounds like the compiler is doing its job

How to translate this to D: const char *const* someConstPtr;

2015-05-09 Thread ParticlePeter via Digitalmars-d-learn
Hi, const char *const* someConstPtr; Error: no identifier for declarator char* Error: declaration expected, not '*' How would I translate this properly to d? Cheers, PP

Re: how does 'shared' affect member variables?

2015-05-09 Thread bitwise via Digitalmars-d-learn
On Sat, 09 May 2015 15:59:57 -0400, tcak t...@gmail.com wrote: If a variable/class/struct etc is not shared, for variables and struct, you find their initial value. For class, you get null. For first timers (I started using shared keyword more than 2 years ago), do not forget that: a shared

Re: how does 'shared' affect member variables?

2015-05-09 Thread Mike via Digitalmars-d-learn
On Saturday, 9 May 2015 at 20:17:59 UTC, bitwise wrote: On Sat, 09 May 2015 15:38:05 -0400, Mike n...@none.com wrote: On Saturday, 9 May 2015 at 18:41:59 UTC, bitwise wrote: Also, I wasn't able to find any thorough documentation on shared, so if someone has a link, that would be helpful.

Re: Lambda functions in D

2015-05-09 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 9 May 2015 at 21:48:05 UTC, Timon Gehr wrote: Well, it is much slower due to all the allocated closures, owed to the fact that the implementations of 'fix' on that page are expected to mirror a particular famous implementation in untyped lambda calculus. In case you have a use

Re: mscoff x86 invalid pointers

2015-05-09 Thread Etienne Cimon via Digitalmars-d-learn
On 2015-05-09 05:44, Baz wrote: On Saturday, 9 May 2015 at 06:21:11 UTC, extrawurst wrote: On Saturday, 9 May 2015 at 00:16:28 UTC, Etienne wrote: I'm trying to compile a library that I think used to work with -m32mscoff flag before I reset my machine configurations.

Re: Lambda functions in D

2015-05-09 Thread tcak via Digitalmars-d-learn
On Saturday, 9 May 2015 at 11:20:10 UTC, Dennis Ritchie wrote: Hi, Can lambda functions or delegates in D to call themselves? Can I write something like this: - import std.stdio; void main() { auto fact = function (int x) = x * { if (x) fact(x - 1); }; assert(fact(10) ==

Re: mscoff x86 invalid pointers

2015-05-09 Thread Baz via Digitalmars-d-learn
On Saturday, 9 May 2015 at 06:21:11 UTC, extrawurst wrote: On Saturday, 9 May 2015 at 00:16:28 UTC, Etienne wrote: I'm trying to compile a library that I think used to work with -m32mscoff flag before I reset my machine configurations. https://github.com/etcimon/memutils Whenever I run `dub

Re: Multiple template alias parameters

2015-05-09 Thread Artur Skawina via Digitalmars-d-learn
On 05/08/15 23:56, Brian Schott via Digitalmars-d-learn wrote: On Friday, 8 May 2015 at 12:44:31 UTC, Artur Skawina wrote: On 05/08/15 03:53, Brian Schott via Digitalmars-d-learn wrote: The problem occurs when I want to register multiple modules to scan for functions. The grammar does not

Lambda functions in D

2015-05-09 Thread Dennis Ritchie via Digitalmars-d-learn
Hi, Can lambda functions or delegates in D to call themselves? Can I write something like this: - import std.stdio; void main() { auto fact = function (int x) = x * { if (x) fact(x - 1); }; assert(fact(10) == 3628800); }

Re: Lambda functions in D

2015-05-09 Thread Manfred Nowak via Digitalmars-d-learn
Dennis Ritchie wrote: auto fact = function (int x) = x * { if (x) fact(x - 1); }; int fact (int x) { return x * ( x1 ? fact(x - 1): 1); }; -manfred

Re: DMD phobos built with contracts check for win?

2015-05-09 Thread Rainer Schuetze via Digitalmars-d-learn
On 05.05.2015 02:03, Dzugaru wrote: I have to compile it myself from sources or is it available somewhere? Was playing with fibers using VisualD + DMD and lack of contract checking (for example call() on fiber in state TERM) leads to bizarre crashes :( The latest (beta) version of Visual D

Re: Lambda functions in D

2015-05-09 Thread Timon Gehr via Digitalmars-d-learn
On 05/09/2015 01:20 PM, Dennis Ritchie wrote: Hi, Can lambda functions or delegates in D to call themselves? Can I write something like this: - import std.stdio; void main() { auto fact = function (int x) = x * { if (x) fact(x - 1); }; assert(fact(10) == 3628800); }

Re: Lambda functions in D

2015-05-09 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 9 May 2015 at 11:49:48 UTC, Timon Gehr wrote: assert((function int(int x)=x?x*__traits(parent,{})(x-1):1)(10)==3628800); Thanks. Yes, it is similar to what I wanted :)

Spawning a console in Windows (similar to forkpty on linux)

2015-05-09 Thread wobbles via Digitalmars-d-learn
This isn't specifically a D question, but seeing as it's for a D library I figure it can go here :) On Windows, I want to be able to spawn a console and then interact with its stdin/out asynchronously, similar to how forkpty [1] works on linux. I'm improving my dexpect library [2] to work

Re: Spawning a console in Windows (similar to forkpty on linux)

2015-05-09 Thread Rikki Cattermole via Digitalmars-d-learn
On 10/05/2015 12:13 a.m., wobbles wrote: This isn't specifically a D question, but seeing as it's for a D library I figure it can go here :) On Windows, I want to be able to spawn a console and then interact with its stdin/out asynchronously, similar to how forkpty [1] works on linux. I'm

Re: Spawning a console in Windows (similar to forkpty on linux)

2015-05-09 Thread wobbles via Digitalmars-d-learn
On Saturday, 9 May 2015 at 12:25:32 UTC, wobbles wrote: On Saturday, 9 May 2015 at 12:16:52 UTC, Rikki Cattermole wrote: On 10/05/2015 12:13 a.m., wobbles wrote: This isn't specifically a D question, but seeing as it's for a D library I figure it can go here :) On Windows, I want to be able

Re: Spawning a console in Windows (similar to forkpty on linux)

2015-05-09 Thread wobbles via Digitalmars-d-learn
On Saturday, 9 May 2015 at 12:16:52 UTC, Rikki Cattermole wrote: On 10/05/2015 12:13 a.m., wobbles wrote: This isn't specifically a D question, but seeing as it's for a D library I figure it can go here :) On Windows, I want to be able to spawn a console and then interact with its stdin/out

Re: Lambda functions in D

2015-05-09 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 9 May 2015 at 14:15:21 UTC, Ali Çehreli wrote: On 05/09/2015 04:59 AM, Dennis Ritchie wrote: On Saturday, 9 May 2015 at 11:49:48 UTC, Timon Gehr wrote: assert((function int(int x)=x?x*__traits(parent,{})(x-1):1)(10)==3628800); Thanks. Yes, it is similar to what I wanted :)

Re: Lambda functions in D

2015-05-09 Thread John Colvin via Digitalmars-d-learn
On Saturday, 9 May 2015 at 14:47:21 UTC, Russel Winder wrote: On Sat, 2015-05-09 at 07:15 -0700, Ali Çehreli via Digitalmars-d-learn wrote: On 05/09/2015 04:59 AM, Dennis Ritchie wrote: On Saturday, 9 May 2015 at 11:49:48 UTC, Timon Gehr wrote: assert((function int(int

Re: Lambda functions in D

2015-05-09 Thread Ali Çehreli via Digitalmars-d-learn
On 05/09/2015 07:47 AM, Russel Winder via Digitalmars-d-learn wrote: Of course none of the implementation can calculate factorial(24) as they are using hardware values which are bounded and cannot store reasonable numbers. Could use iota. Oh no we can't as BigNums are not integral. I don't

Re: Spawning a console in Windows (similar to forkpty on linux)

2015-05-09 Thread wobbles via Digitalmars-d-learn
On Saturday, 9 May 2015 at 12:48:16 UTC, Kagamin wrote: On Saturday, 9 May 2015 at 12:26:58 UTC, wobbles wrote: What I mean is, if the cmd.exe hasnt flushed it's output, my cmdPid.stdout.readln (or whatever) will block until it does. I dont really want this. Are you sure cmd is the culprit?

Re: Safe Usage of Mutable Ranges in foreach scopes

2015-05-09 Thread via Digitalmars-d-learn
On Friday, 8 May 2015 at 11:25:26 UTC, Per Nordlöw wrote: Could the scope keyword be used here? Could the work done in DIP-25 be reused here, Walter? I had `scope!(const ...)` in my original proposal [1] to handle exactly this problem. The latest iteration doesn't have it as an explicit

Re: Lambda functions in D

2015-05-09 Thread Russel Winder via Digitalmars-d-learn
On Sat, 2015-05-09 at 07:15 -0700, Ali Çehreli via Digitalmars-d-learn wrote: On 05/09/2015 04:59 AM, Dennis Ritchie wrote: On Saturday, 9 May 2015 at 11:49:48 UTC, Timon Gehr wrote: assert((function int(int x)=x?x*__traits(parent,{})(x-1):1)(10)==3628800); Thanks. Yes, it is similar

Re: Spawning a console in Windows (similar to forkpty on linux)

2015-05-09 Thread Kagamin via Digitalmars-d-learn
On Saturday, 9 May 2015 at 12:26:58 UTC, wobbles wrote: What I mean is, if the cmd.exe hasnt flushed it's output, my cmdPid.stdout.readln (or whatever) will block until it does. I dont really want this. Are you sure cmd is the culprit? It should have sensible buffering. Also do you want just

Re: Spawning a console in Windows (similar to forkpty on linux)

2015-05-09 Thread wobbles via Digitalmars-d-learn
On Saturday, 9 May 2015 at 13:00:01 UTC, wobbles wrote: On Saturday, 9 May 2015 at 12:48:16 UTC, Kagamin wrote: On Saturday, 9 May 2015 at 12:26:58 UTC, wobbles wrote: What I mean is, if the cmd.exe hasnt flushed it's output, my cmdPid.stdout.readln (or whatever) will block until it does. I

Re: Lambda functions in D

2015-05-09 Thread Ali Çehreli via Digitalmars-d-learn
On 05/09/2015 04:59 AM, Dennis Ritchie wrote: On Saturday, 9 May 2015 at 11:49:48 UTC, Timon Gehr wrote: assert((function int(int x)=x?x*__traits(parent,{})(x-1):1)(10)==3628800); Thanks. Yes, it is similar to what I wanted :) Also interesting: http://rosettacode.org/wiki/Y_combinator#D

Re: Lambda functions in D

2015-05-09 Thread Ali Çehreli via Digitalmars-d-learn
On 05/09/2015 10:45 AM, Russel Winder via Digitalmars-d-learn wrote: On Sat, 2015-05-09 at 09:49 -0700, Ali Çehreli via Digitalmars-d-learn wrote: […] BigInt factorial(size_t n) { return bigInts(1).take(n).reduce!((a, b) = a *= b); } I wonder if that should be a * b rather than a *=

Re: Spawning a console in Windows (similar to forkpty on linux)

2015-05-09 Thread Baz via Digitalmars-d-learn
On Saturday, 9 May 2015 at 13:01:27 UTC, wobbles wrote: On Saturday, 9 May 2015 at 13:00:01 UTC, wobbles wrote: On Saturday, 9 May 2015 at 12:48:16 UTC, Kagamin wrote: On Saturday, 9 May 2015 at 12:26:58 UTC, wobbles wrote: What I mean is, if the cmd.exe hasnt flushed it's output, my

Re: Lambda functions in D

2015-05-09 Thread Russel Winder via Digitalmars-d-learn
On Sat, 2015-05-09 at 09:49 -0700, Ali Çehreli via Digitalmars-d-learn wrote: […] BigInt factorial(size_t n) { return bigInts(1).take(n).reduce!((a, b) = a *= b); } I wonder if that should be a * b rather than a *= b? It turns out that 2.067 fixes the integrality of BigInts so:

how does 'shared' affect member variables?

2015-05-09 Thread bitwise via Digitalmars-d-learn
What does 'shared' do to member variables? It makes sense to me to put it on a global variable, but what sense does it make putting it on a member of a class? What happens if you try to access a member of a class/struct instance from another thread that is not marked 'shared'? Also, I

Re: how does 'shared' affect member variables?

2015-05-09 Thread Mike via Digitalmars-d-learn
On Saturday, 9 May 2015 at 18:41:59 UTC, bitwise wrote: Also, I wasn't able to find any thorough documentation on shared, so if someone has a link, that would be helpful. Here are a few interesting links: Iain Buclaw (lead developer for GDC) with his interpretation:

Re: how does 'shared' affect member variables?

2015-05-09 Thread tcak via Digitalmars-d-learn
On Saturday, 9 May 2015 at 18:41:59 UTC, bitwise wrote: What does 'shared' do to member variables? It makes sense to me to put it on a global variable, but what sense does it make putting it on a member of a class? What happens if you try to access a member of a class/struct instance from

Re: mscoff x86 invalid pointers

2015-05-09 Thread extrawurst via Digitalmars-d-learn
On Saturday, 9 May 2015 at 00:16:28 UTC, Etienne wrote: I'm trying to compile a library that I think used to work with -m32mscoff flag before I reset my machine configurations. https://github.com/etcimon/memutils Whenever I run `dub test --config=32mscoff` it gives me an assertion failure,