Re: Bug? taskPool.map() with bufSize and writeln() gets stuck
On Saturday, 11 February 2012 at 01:31:29 UTC, Ali Çehreli wrote: Sorry for the double-post; I have asked the same question on D.learn earlier but I think this is more of a question to this forum. Tested on Ubuntu 11.10 64-bit dmd. The following program gets stuck during the writeln() call. - Note that the foo() call alone works fine. - Also note that the program works fine when there is no writeln() call nor foo() call. All elements get processed in that case and the results are ignored. Am I using taskPool.map incorrectly or is this a bug? Can you help identify where the problem may be? How is writeln() using the range differently than foo() to cause this behavior? import std.stdio; import std.parallelism; import core.thread; int func(int i) { writeln("processing ", i); return i; } void main() { auto results = taskPool.map!func([1,2,3,4,5,6,7,8], 2); writeln(results); // <-- Gets stuck HERE foo(results); // this works fine } void foo(R)(R range) { for ( ; !range.empty; range.popFront()) { writeln(range.front); } } Thank you, Ali For what I see, maybe that's because it's a "non-random access ranges". So to access "results", you need access from it's aggregate... try this inside your main: foreach(int r; results) writeln(r); // foo(results); // this works fin
Re: [your code here]
Nice, but just a little thing: switch(toUpper(returned)) { case 'Y': break checkLoop; case 'H': {low=guess; break;} case 'L': {high=guess; break;} default: break; } PS: Yeah you can you tolower() too! On Friday, 17 February 2012 at 23:50:32 UTC, Matt Soucy wrote: #!/usr/bin/rdmd import std.stdio; void main() { uint guesses=0, high=100, low=0, guess=50; char returned; writef("Please choose a number between %s and %s.\n"); writef("Press enter to begin.",low,high); readln(); checkLoop: do { guess = (high-low)/2+low; // Avoid overflow (shouldn't occur) writef("Is your number %s? [(y)es, (h)igher, (l)ower] ", guess); readf("%c", &returned); readln(); switch(returned) { case 'y','Y': break checkLoop; case 'h','H': {low=guess; break;} case 'l','L': {high=guess; break;} default: break; } } while(++guesses); writef("I guessed your number in %s moves!\n", guesses); } This piece is something I wrote quickly for /r/dailyprogrammer (By the way, is the person who has been posting D solutions to that on here?) It's a really simple piece, but it shows %s, breaking from a loop from inside a switch, etc.
Re: D as a prototyping language (for C/C++ projects)
On Tuesday, 26 February 2013 at 15:26:17 UTC, Craig Dillabaugh wrote: I was curious to know if anyone else uses D like this. I usually do this, but in a little different way. I wrote my code in a interpreted language, and then I port to D or C languages.
Re: The kind of documentation people like
On Wednesday, 6 March 2013 at 08:17:58 UTC, Walter Bright wrote: What I get from this is that people really like PHP's documentation style where users can add to it. Of course, plus the rank system, (where the best answers appears first), you "almost" have a winner. I said "almost", because I've seen answers that were classified ("despite working") above other better or optmized answers because of the date they were posted. IMHO maybe in programming side, it would be nice to have an additional technical vote walking together with rank system.
Re: request switch statement with common block
On Saturday, 3 August 2013 at 14:38:48 UTC, JS wrote: switch (cond) common: always executed code here case A : etc... } instead of if (cond) { always executed code here } switch (cond) case A : etc... } which requires modification of the condition twice when necessary Why don't you just: switch(cond) { default: // YOUR COMMON HERE case A: ... break; ... }
Re: request switch statement with common block
On Monday, 5 August 2013 at 04:07:55 UTC, Andre Artus wrote: Andre Artus: int number; string message; switch (number) { default: // valid: ends with 'throw' throw new Exception("unknown number"); case 3: message ~= "three "; break; case 4: message ~= "four "; continue; case 5: message ~= "five "; goto case; case 6: message ~= "six "; break; case 1: case 2: message = "one or two"; } With the inclusion of 'default' the condition covers the whole range of 'int'. The programmer may only want the pre and post code to be executed for every other case (1..6). MattCoder: Like I said, it would be nice if we could extend some D features without change the compiler source, maybe like macros in LISP. It may not always be the case, but in my experience this often leads to write-only code. I'm pretty new to D, so I'm not quite up to speed with the metaprogramming abilities, but I'm under the impression that this is what mixin's are for. Well I'm not experienced too, but mixin's for what I know just works in compiler time right? But anyway it would be possible to write my own switch version with mixin? I really would like to see this. Matheus.