Re: String Metaprogramming
On Saturday, 18 July 2015 at 13:48:20 UTC, Clayton wrote: Am new to D programming, am considering it since it supports compile-time function execution . My challenge is how can I re-implement the function below so that it is fully executed in compile-time. The function should result to tabel1 being computed at compile-time. There seems to be a lot of mutation happening here yet I have heard no mutation should take place in meta-programming as it subscribes to functional programming paradigm. void computeAtCompileTime( ref string pattern ,ref int[char] tabel1){ int size = to!int(pattern.length) ; foreach( c; ALPHABET){ tabel1[c] = size; } for( int i=0;isize -1 ; ++i){ //Initialise array tabel1[pattern[i]] = size -i-1; pragma(msg, format(reached pattern table1[pattern[i]]=(%s) here, table1[pattern[i]].stringof ~ v=~ (size -i-1).stringof)); } } Actually, the main things you can't do in CTFE are FPU math operations (much of std.math has issues unfortunately), compiler intrinsics, pointer/union operations, and I/O. I don't immediately see anything that will cause issues with CTFE in that function. However, sometimes the compiler isn't smart enough to figure out that it should be doing that, but you can force the compiler to try CTFE using this pattern int ctfeFunc() { } void main() { enum val = ctfeFunc(); } enums are manifest constants, and thus must be computable at compile time, so this will issue an error if something in your function can't CTFE.
Re: std.concurrency: The fate of unmatched messages
On Saturday, 11 July 2015 at 02:15:02 UTC, ketmar wrote: so simply don't receive the messages you don't need right now. as i said, `receive()` doesn't look to top message only, it scans the whole mailbox, trying to find a message that matches. you can use `receiveTimeout()` to do nothing if there are no suitable messages. you can also adjust mailbox size and mode. Okay, so it doesn't purge unrecognized messages, then! That's what I needed to know!
Re: std.concurrency: The fate of unmatched messages
On Friday, 10 July 2015 at 23:39:30 UTC, ketmar wrote: this way your `receive` will get all messages. simply do nothing in `Variant` handler to drop messages you don't want to process. [1] http://dlang.org/phobos/std_concurrency.html#.receive The thing is, I want to do receive() in two separate places, and I want each receive() call to leave the other's messages alone, not drop them.
std.concurrency: The fate of unmatched messages
I'm putting together a program that uses std.concurrency to handle two child threads from the main thread; The kicker here is that both the children do very different things. And I would like to handle receive() calls for them in separate locations. But from what I can tell, each thread has only one mailbox. And none of the documentation i can find for std.concurrency mentions what happens when one receive() call gets a message it doesn't understand. Are unmatched messages left in the Mailbox, or are they discarded? (I am admittedly strongly hoping it is the former) And if the latter, is there any way to actually give a single thread multiple mailboxes?
Re: Why .dup not work with multidimensional arrays?
It's because arrays are references types, and .dup is a strictly shallow copy, so you're getting two outer arrays that reference the same set of inner arrays. You'll have to duplicated each of the inner arrays yourself if you need to make a deep copy. On Friday, 8 May 2015 at 02:15:38 UTC, Dennis Ritchie wrote: Hi, Should the method .dup work with multidimensional arrays for copying? - import std.stdio; void main() { auto a = [1, 2, 3]; auto b = a.dup; b[] *= 2; writeln(a = , a); // [1, 2, 3] // OK writeln(b = , b); // [2, 4, 6] // OK auto c = [[[1, 2, 3], [4, 5, 6, 7, 8]], [[9, 10], [11, 12, 13]]]; auto d = c.dup; writeln(d[0][1][1 .. $ - 1] = , d[0][1][1 .. $ - 1]); d[0][1][1 .. $ - 1] *= 3; writeln(c = , c); // [[[1, 2, 3], [4, 15, 18, 21, 8]], // [[9, 10], [11, 12, 13]]] // wrong writeln(d = , d); // [[[1, 2, 3], [4, 15, 18, 21, 8]], // [[9, 10], [11, 12, 13]]] // OK } - http://ideone.com/Ddtm47 I thought the slice of the array c[0][1][1 .. $ - 1] = [5, 6, 7] not had to change to [15, 18, 21] by multiplying by 3.