Re: How do I exhaust a thread's message queue?

2011-04-01 Thread Andrej Mitrovic
Actually I have a bug in `foo()`, the switch statement is executed even if I didn't get a message back. Here's a fix: void foo() { int result; bool gotMessage; while (true) { gotMessage = receiveTimeout(1000, (int x) { result = x; }

Re: How do I exhaust a thread's message queue?

2011-04-01 Thread Andrej Mitrovic
Btw disregard that "handle" function, I've used it first but then decided to change `result` directly in the receiveTimeout function. It's better that way.

Re: How do I exhaust a thread's message queue?

2011-04-01 Thread Andrej Mitrovic
I'm good at answering my own questions. :p import std.stdio; import std.concurrency; import core.thread; void main() { auto workThread = spawn(&foo); int delay = 500; int command = 0; while(true) { Thread.sleep( dur!("msecs")( delay += 100 ) ); workThread.send

How do I exhaust a thread's message queue?

2011-04-01 Thread Andrej Mitrovic
Note this is just pseudocode: // worker thread void doWork() { // while there's still stuff in the message queue while (messagesInQueue) { result = receiveOnly!int(); switch(result) { // main thread could be enabling or disabling features this w

Re: The is expression

2011-04-01 Thread Caligo
On Fri, Apr 1, 2011 at 5:14 PM, enuhtac wrote: > Hello, > > the "is" expression is a great feature of D - but its use is not very > intuitive, at least for me. > I'm trying to write a template that figures out if the template > parameter is of a given type. > This is the type I would like to check

The is expression

2011-04-01 Thread enuhtac
Hello, the "is" expression is a great feature of D - but its use is not very intuitive, at least for me. I'm trying to write a template that figures out if the template parameter is of a given type. This is the type I would like to check for: struct A( T, string s ) { ... }; One possibility to a

Re: We could use a hasExt function in std.path

2011-04-01 Thread Andrej Mitrovic
Match a single extension or any number of extensions. I've said "range", but I didn't mean a custom type. Just that it works with either 1 value or an array of values.

Re: We could use a hasExt function in std.path

2011-04-01 Thread spir
On 04/01/2011 11:03 PM, Andrej Mitrovic wrote: At least on Windows, as far as I know, the casing of a file extension doesn't come into play. But when comparing extensions, you have to be careful to lowercase the result of `getExt()`, for example: foreach (string name; dirEntries(curdir, SpanMo

Re: We could use a hasExt function in std.path

2011-04-01 Thread Andrej Mitrovic
On 4/1/11, Andrej Mitrovic wrote: > I often have to search for files that have a certain extension. Having to > expand the code to the following becomes ugly real fast: > > foreach (string name; dirEntries(curdir, SpanMode.shallow)) > { > if (name.isFile && name.hasExt.tolower == "ini" || >

We could use a hasExt function in std.path

2011-04-01 Thread Andrej Mitrovic
At least on Windows, as far as I know, the casing of a file extension doesn't come into play. But when comparing extensions, you have to be careful to lowercase the result of `getExt()`, for example: foreach (string name; dirEntries(curdir, SpanMode.shallow)) { if (name.isFile && name.getExt

Re: null Vs [] return arrays

2011-04-01 Thread Steven Schveighoffer
On Fri, 01 Apr 2011 11:52:47 -0400, Regan Heath wrote: On Fri, 01 Apr 2011 13:38:45 +0100, Steven Schveighoffer wrote: On Fri, 01 Apr 2011 06:38:56 -0400, Regan Heath wrote: On Mon, 28 Mar 2011 17:54:29 +0100, bearophile wrote: Steven Schveighoffer: So essentially, you are getti

Re: A use case for fromStringz

2011-04-01 Thread Andrej Mitrovic
On 4/1/11, Jacob Carlborg wrote: > In those cases, doesn't the function return the length of the filled > data or something like that? I know what you mean. I would expect a C function to do just that, but in this case it does not. Its lame but I have to deal with it.

Re: null Vs [] return arrays

2011-04-01 Thread Regan Heath
On Fri, 01 Apr 2011 13:38:45 +0100, Steven Schveighoffer wrote: On Fri, 01 Apr 2011 06:38:56 -0400, Regan Heath wrote: On Mon, 28 Mar 2011 17:54:29 +0100, bearophile wrote: Steven Schveighoffer: So essentially, you are getting the same thing, but using [] is slower. It seems I wa

Re: null Vs [] return arrays

2011-04-01 Thread Steven Schveighoffer
On Fri, 01 Apr 2011 06:38:56 -0400, Regan Heath wrote: On Mon, 28 Mar 2011 17:54:29 +0100, bearophile wrote: Steven Schveighoffer: So essentially, you are getting the same thing, but using [] is slower. It seems I was right then, thank you and Kagamin for the answers. This may be sli

Re: Commenting out a print slows my code?

2011-04-01 Thread vincent feltkamp
I managed to get the file, and even compile it, but apparently the type Ticks doesn't exists any more, it is now (DMD2.052) TickDuration, with methods TickDuration.seconds (msecs, hnsecs, ...). on my computer, it does not generate slower code without the writeln than with. ( .38-.39 secs with, .

Re: null Vs [] return arrays

2011-04-01 Thread spir
On 04/01/2011 12:38 PM, Regan Heath wrote: On Mon, 28 Mar 2011 17:54:29 +0100, bearophile wrote: Steven Schveighoffer: So essentially, you are getting the same thing, but using [] is slower. It seems I was right then, thank you and Kagamin for the answers. This may be slightly OT but I ju

Re: null Vs [] return arrays

2011-04-01 Thread Torarin
2011/4/1 Regan Heath : > On Mon, 28 Mar 2011 17:54:29 +0100, bearophile > wrote: >> >> Steven Schveighoffer: >> >>> So essentially, you are getting the same thing, but using [] is slower. >> >> It seems I was right then, thank you and Kagamin for the answers. > > This may be slightly OT but I just

Re: null Vs [] return arrays

2011-04-01 Thread bearophile
Regan Heath: > conceptually it's nice to be able to express (exists but is empty) and > (does not exist). You may want to express that, but for the implementation of the language those two situations are the same, because in the [] literal the ptr is null. So I think it's better for the progr

Re: null Vs [] return arrays

2011-04-01 Thread Regan Heath
On Mon, 28 Mar 2011 17:54:29 +0100, bearophile wrote: Steven Schveighoffer: So essentially, you are getting the same thing, but using [] is slower. It seems I was right then, thank you and Kagamin for the answers. This may be slightly OT but I just wanted to raise the point that concept

Re: A use case for fromStringz

2011-04-01 Thread Jacob Carlborg
On 3/31/11 11:18 PM, Andrej Mitrovic wrote: Actually, this still suffers from the problem when the returned char* doesn't have a null terminator. It really sucks when C code does that, and I've just experienced that. There is a solution though: In those cases, doesn't the function return the le