Re: Faster Command Line Tools in D
On Wednesday, 24 May 2017 at 13:39:57 UTC, Mike Parker wrote: Some of you may remember Jon Degenhardt's talk from one of the Silicon Valley D meetups, where he described the performance improvements he saw when he rewrote some of eBay's command line tools in D. He has now put the effort into crafting a blog post on the same topic, where he takes D version of a command-line tool written in Python and incrementally improves its performance. The blog: https://dlang.org/blog/2017/05/24/faster-command-line-tools-in-d/ Reddit: https://www.reddit.com/r/programming/comments/6d25mg/faster_command_line_tools_in_d/ There are repeated references over usage of D at Netflix for machine learning. It will be a very helpful boost if someone comes up with any reference or a post regarding how D is used at Netflix and addition of Netflix to https://dlang.org/orgs-using-d.html will be amazing. References : https://news.ycombinator.com/item?id=14064012 https://news.ycombinator.com/item?id=14413546
Optimising JSON parsing leads to wierd execution timings
Hi, Sorry for the double post. I have asked a question at Stackoverflow regarding this : https://stackoverflow.com/questions/42992507/get-float-value-out-of-jsonvalue-in-dlang . I have a `rating` field that might have 3 which parses to JSONValue.integer or 3.4 which parses to JSONValue.floating and I need to use float. I was using exceptions that was causing the program to be slow as per the profile information. Now I have used an if clause as suggested by Adam in the answer. Though the execution time for the relevant function that used exceptions earlier reduced the program was still taking the same time. So I profiled again and now the time for JSON parsing has suddenly increased as per the profile. I thought it was due to using .type and I returned a hardcoded number for the function get_number and the time to write to terminal increased. I don't know why reducing the time on one function leads to increase in another function. JSON file : gist.github.com/tirkarthi/c4b2ea745f15dbc6a01327b86c1d059f Compiler : ldc2 with -O3 and -release flags LLVM : LLVM 4.0 Operating System : Mac OS (Early 2015 model) with 4GB RAM Original program with exceptions : import std.net.curl; import std.exception; import std.json; import std.stdio; import std.file; import std.algorithm; import std.array; import std.conv; import std.string; auto fmt = "%35s | %10s | %10s | %10s | %15s"; auto value_fmt = "%35s | %10.2f | %10.0f | %10.2f | %15s"; void print_header() { writeln("---"); writefln(fmt, "Name", "Price", "Window", "Rating", "Type"); writeln("---"); } float get_number(T)(T item) { float output = 0; try { output = to!float(item.integer); } catch(Exception e) { output = to!float(item.floating); } return to!float(output); } void print_item(T)(T item) { writefln(value_fmt, item["Tvs"].str, item["MinFare"].get_number(), item["WnSt"].get_number(), item["Rtg"]["totRt"].get_number(), item["BusCategory"]["IsSleeper"]); } void main() { auto content = readText("sample.json"); auto parsed = parseJSON(content); auto raw = parsed["SRD"][0]["RIN"][0]["InvList"].array; auto filtered = raw.filter!(item => to!bool(to!string(item["BusCategory"]["IsAc"]))); print_header(); foreach(item; filtered) { print_item(item); } }
Re: DConf 2017 Schedule
On Thursday, 23 March 2017 at 12:34:13 UTC, Nicholas Wilson wrote: On Wednesday, 15 March 2017 at 15:20:03 UTC, Joakim wrote: On Tuesday, 14 March 2017 at 16:12:56 UTC, Mike Parker wrote: Fresh from the D Foundation HQ, the DConf 2017 schedule [1] is now available for your perusal. If you haven't registered yet, you have just over five weeks to get it done. The registration deadline has been set for April 23, so don't procrastinate. Even better, head over to the registration page [2] and do it now! [1] http://dconf.org/2017/schedule/ [2] http://dconf.org/2017/registration.html Killer lineup, makes me wish I was going, is it on reddit? I haven't seen it there yet. someone should definitely put it there. Submitted to Reddit : https://www.reddit.com/r/programming/comments/612sy4/dconf_2017_schedule_announced_scott_meyers_is_one/
Re: Release Candidate 2.073.0-rc1
On Wednesday, 18 January 2017 at 13:48:06 UTC, Martin Nowak wrote: First release candidate for 2.073.0. http://dlang.org/download.html#dmd_beta http://dlang.org/changelog/2.073.0.html Comes with a couple of more fixes: https://github.com/dlang/dmd/compare/v2.073.0-b2...v2.073.0-rc1 https://github.com/dlang/druntime/compare/v2.073.0-b2...v2.073.0-rc1 https://github.com/dlang/phobos/compare/v2.073.0-b2...v2.073.0-rc1 https://github.com/dlang/dub/compare/v1.2.0-beta.2...v1.2.0-rc.1 Please report any bugs at https://issues.dlang.org -Martin Thanks a lot for the RC. I think the text "to be released Jan 18, 2017" can be removed since its slightly confusing.
Language server protocol implementation for D
Rust is making good progress on the IDE aspect with the announcement : http://www.jonathanturner.org/2017/01/rls-alpha-release.html. HN discussion : https://news.ycombinator.com/item?id=1348 It will be good to see the protocol implemented so that many tools and IDEs can use the interface to provide better tooling for development. https://github.com/Microsoft/language-server-protocol https://github.com/Microsoft/language-server-protocol/wiki/Protocol-Implementations
Re: Need some help understanding PyD
On Monday, 9 January 2017 at 06:22:14 UTC, Saurabh Das wrote: PS: Noticed something off. My python installation is 3.4.3: Python 3.4.3 (default, Sep 14 2016, 12:36:27) [GCC 4.8.4] on linux However when I run: context.py_stmts("import sys"); context.py_stmts("print(sys.version)"); I get: 3.4.0 (default, Apr 11 2014, 13:08:40) [GCC 4.8.2] Also, when I import numpy from python3, it works, but if I do: context.py_stmts("import numpy"); I get this error: pyd.exception.PythonException@source/app.d(20): ImportError: /usr/lib/python3.4/lib-dynload/_ctypes.cpython-34m-x86_64-linux-gnu.so: undefined symbol: _PyTraceback_Add I think you need to upgrade Python. I googled "_PyTraceback_Add" and got this http://stackoverflow.com/questions/33223713/python-ctypes-import-error-in-virtualenv . Also refer to this comment http://stackoverflow.com/questions/33223713/python-ctypes-import-error-in-virtualenv#comment54266298_33223713 . Hope this helps.
Re: Learning resources for std.experimental.allocator
On Friday, 6 January 2017 at 23:39:09 UTC, Ryan wrote: On Friday, 6 January 2017 at 03:28:43 UTC, Chris Wright wrote: There are some other interesting things you can do with this, though, regarding tracking how you use memory. Or you could use it to better benchmark malloc vs GC for your application. I did this just to see what the difference was and I was surprised by the results. Just using the allocator interface with the GC caused a speed up, then the additional speed up from using malloc/free was very small in comparison. https://forum.dlang.org/post/rurbbpuqnfepllecq...@forum.dlang.org Thanks a lot for sharing this.
Re: Learning resources for std.experimental.allocator
On Thursday, 5 January 2017 at 13:16:44 UTC, Edwin van Leeuwen wrote: On Thursday, 5 January 2017 at 11:09:01 UTC, xtreak wrote: Can someone explain me the actual benefits of using this and if so any benchmarks explaining the advantage. Benefits compared to what? Compared to using the GC? Yes, I want to know the benefits with respect to GC and if its going to reduce the usage of GC across the language implementation.
Learning resources for std.experimental.allocator
I am newbie to D learning it for sometime using Ali's book. I came across std.experimental.allocator and read through http://dlang.org/library/std/experimental/allocator/building_blocks.html . Can someone explain me the actual benefits of using this and if so any benchmarks explaining the advantage. Maybe its too advanced for me as a beginner now its just I am curious over the usage and applications with a simple hello world like example explaining what this library will accomplish. I asked it previously at https://www.reddit.com/r/programming/comments/4hti33/dconf_2016_is_streaming_right_now/d2satic/ but still I don't understand the exact applications of the same. A simple hello world like example over its advantage will be very much helpful. PS : Sorry for the crosspost. I posted it to learn group but didn't receive any suggestions on the same at http://forum.dlang.org/post/bhnwudqeanbxjgooo...@forum.dlang.org
Resources for using std.allocator
I am newbie to D learning it for sometime using Ali's book. I came across std.experimental.allocator and read through http://dlang.org/library/std/experimental/allocator/building_blocks.html . Can someone explain me the actual benefits of using this and if so any benchmarks explaining the advantage. Maybe its too advanced for me as a beginner now its just I am curious over the usage and applications with a simple hello world like example explaining what this library will accomplish. I asked it previously at https://www.reddit.com/r/programming/comments/4hti33/dconf_2016_is_streaming_right_now/d2satic/ but still I don't understand the exact applications of the same.
Re: DConf 2017: Bigger, Badder, and Berliner! Call for Submissions now open
On Monday, 14 November 2016 at 19:49:26 UTC, Andrei Alexandrescu wrote: Please join us at DConf 2017, the conference of the D programming language in Berlin, Germany, May 4-6 2017. We're happy to announce that the D Language Foundation is cooperating again with Sociomantic to organize DConf 2017 in Berlin for the second time. Same location, same dates, but of course a whole new experience! The D programming language has improved dramatically this year thanks to more focus brought up by the D Language Foundation, better participation from corporate users and worldwide volunteers, and the advent of world-class open-source libraries such as Sociomantic's Tsunami and Ilya Yaroshenko's GLAS. The D Language Foundation has accumulated a war chest and announced a scholarship that already enrolls four MSc students. DConf is the main face-to-face event for everyone and everything related to the D language and environment. The 2017 edition will be held in Europe for the second time, following last year's smashing success. Which, of course, we plan to smash again! Call for Submissions We are looking forward to your submission for a paper, talk, demo, panel, or research report (new!) for DConf 2017. The topics of choice are anything and everything related to the D language. For more details, check the conference page: http://dconf.org/2017/index.html Great news! A couple of js, svg and png files are missing. I tried to raise an issue in dconf.org at Github but it seems issues are disabled. I tried force reload on Mac OSX Chrome but the issue persists. Hope someone can verify the issue. Seems it could not be reported at issues.dlang.org. Hope dlang.org could also be updated with the news. Filed an issue at https://issues.dlang.org/show_bug.cgi?id=16693 Thanks!
Re: .array changes the order
On Thursday, 12 May 2016 at 13:43:10 UTC, thedeemon wrote: On Thursday, 12 May 2016 at 10:17:19 UTC, xtreak wrote: Thanks a lot. Can you kindly elaborate a little more on File.byLine with an example of the scenario so that I don't get bitten by it. File.byLine.array works as expected for me. A little more explanation on the permutations will also be helpful since joiner.map!array converts the subranges to arrays, so does joiner work by mutating state if so how does it do. With some ranges the value they return by .front is only valid until the next call to popFront(). For example, File.byLine() reuses its buffer so after popFront() is called the buffer contains different data and if you had references to the contents of previously returned value they become invalid. This is why byLineCopy() was added. In the same vein permutations() returns a range that has a mutable array of indices inside, which changes every time popFront() is called, and since every value returned by its .front refers to that indices array, if you collect such permutations they will all use the same array of indices and show the same order of elements, the same permutation. Because of this mutable nature of some ranges it's important to understand in which order calls to .front and .popFront() happen. The array() function calls popFront on its input in a loop, consuming the mutable ranges, while map() does not. So in r.map!f.array function f will receive different valid values, before they get invalidated in the loop of array(). But if they contain references to something mutable, it makes sense to make copies before the thing they refer to mutates. Thanks a lot for the info that really clears a lot of things for me :) I see from the source that byLineCopy makes a .dup on each line and cached at https://github.com/dlang/phobos/blob/master/std/stdio.d#L2029-L2034 with gotFront when front is called a lot of times. I could see a function called emplaceref being used in array. Any ideas on that please.
Re: .array changes the order
On Thursday, 12 May 2016 at 10:02:46 UTC, thedeemon wrote: On Thursday, 12 May 2016 at 09:44:39 UTC, xtreak wrote: I came across the issue where using .array after .joiner caused the changes to the output. The program is at https://dpaste.dzfl.pl/0885ba2eddb4 . I tried to debug through the output but I couldn't get the exact issue. It will be helpful if someone confirms this as a bug. It's not a bug per se, just probably documentation being not clear enough. Essentially it's the same issue as with File.byLine: a range that mutates its state, so it's ok to consume lazily but if you just store references (as array() does) you get references to the same mutated value as result. Quick fix: r.chunks(2).map!permutations.joiner.map!array.array.writeln; i.e. copy each permutation to separate array before it's gone. Thanks a lot. Can you kindly elaborate a little more on File.byLine with an example of the scenario so that I don't get bitten by it. File.byLine.array works as expected for me. A little more explanation on the permutations will also be helpful since joiner.map!array converts the subranges to arrays, so does joiner work by mutating state if so how does it do.
Re: Intermediate level D and open source projects to study
On Thursday, 12 May 2016 at 00:35:04 UTC, Jon D wrote: On Wednesday, 11 May 2016 at 18:41:47 UTC, xtreak wrote: Hi, I am a D newbie. I worked through D programming language and programming in D books. I primarily use Python daily. I will be happy to know how I can go to intermediate level in D. It will be hepful to have projects in D of high quality and also beginner friendly code that I can study to improve my D. [snip] Might not be exactly what you are looking for, but I recently open-sourced some command line utilities you could take look at. They are real apps in that they take command line arguments, have help, error handling, etc. But, they are doing relatively straightforward tasks, things you might do in Python also. A caution: I'm relatively new to D as well, and there are likely places where the code could be more idiomatic D. Utilities are at: https://github.com/eBay/tsv-utils-dlang. The readme has a section labeled "The code" that describes the code structure. Thanks for the reply I think I saw your post in reddit sometime back. I will take a look. Since its under ebay an off topic and curious question so is it still in production? How does ebay folks consider using D in production and is D actively in ebay?
Intermediate level D and open source projects to study
Hi, I am a D newbie. I worked through D programming language and programming in D books. I primarily use Python daily. I will be happy to know how I can go to intermediate level in D. It will be hepful to have projects in D of high quality and also beginner friendly code that I can study to improve my D. In the Python community Flask, requests, etc. are recommended for study. Are there any projects that I can use for study. I looked into phobos but I guess I am still not very comfortable with the code in phobos. I would like to play around with idiomatic code so that I can learn more. Reimplementing or porting some projects from Python are good but I will be happy to hear from experts the recommended projects and things to look into to get to intetmediate level. I looked into the wiki but it lists debuggers, dev tools and others. Kindly point to the discussion since I couldn't find them. Hope its the right place to ask.
Re: DConf 2015 livestreaming day 1: post feedback here
On Wednesday, 4 May 2016 at 15:26:18 UTC, Vladimir Panteleev wrote: On Thursday, 28 May 2015 at 00:54:30 UTC, Andrei Alexandrescu wrote: John Colvin's experiment is great and we want to make it a full success. Please post here feedback and suggestions for tomorrow's DConf streaming. Thanks! -- Andrei Just a FYI to everyone posting in this thread, this thread was originally posted in 2015, and the first 7 posts were regarding DConf 2015. Thanks for pointing that out :) :)
Re: DConf 2015 livestreaming day 1: post feedback here
On Thursday, 28 May 2015 at 00:54:30 UTC, Andrei Alexandrescu wrote: John Colvin's experiment is great and we want to make it a full success. Please post here feedback and suggestions for tomorrow's DConf streaming. Thanks! -- Andrei Relevant post at Reddit : https://www.reddit.com/r/programming/comments/4hti33/dconf_2016_is_streaming_right_now/
Re: What does alias do?
On Saturday, 23 April 2016 at 20:01:00 UTC, ag0aep6g wrote: On 23.04.2016 21:49, xtreak wrote: I am a D newbie from Python and I am trying to grok alias. Is alias like Python does as below L = [] myextend = L.extend L.myextend My Python isn't too great, but I think this is more similar to function pointers or delegates in D. Renaming imported function from itertools import permutations as p p([1, 2], 2) Yes, that's similar. A renamed import creates an alias. For example, `import std.algorithm: p = permutations;` creates an alias `p` for std.algorithm.permutations. Is D aliasing the same as above? How does aliasing types help like below alias intList = LinkedList!int Is the above like a partially applied template as in LinkedList!int([1, 2, 3]) and hence can I use it like intList([1, 2, 3])? No, the template isn't partially applied, it's fully instantiated (and results in a type). The alias declaration just makes `intList` an alternative name for `LinkedList!int`. import std.array; import std.range; import std.algorithm; import std.stdio; T test(alias f, T)(T num) { return f(num); } T test1(T, V)(T num, V f){ return f(num); } void main() { writeln("hello world"); writeln(1.iota .map!(a => a * a) .take(5)); writeln(test!(z => z * z)(10)); writeln(test1(10, ((z) => z *z))); writeln(test1(10, function int(int z) { return z * z; })); } What is the difference between passing as alias and then passing it as lambda. Does it involve any cost. Also the second form of short notation throws an error that it returns void. Kindly help me on this as now alias is not pointing to a named symbol so is there any cost and why alias is preferred
Why does map take lambda as a template parameter
map takes lambda as a template parameter and so does filter and many other functions. Sometimes they take something other than lambda as a template parameter. Eg. In case of to!int("5") int is a type and hence might need it as a template parameter but why does map and others take it as template parameter. Adam D Ruppe pointed out in IRC it helps in inlining and optimization. Is there a thumb rule to decide this so that my functions too can benefit the performance and hence I could structure and understand my code better.
Re: What does alias do?
On Saturday, 23 April 2016 at 19:49:46 UTC, xtreak wrote: I am a D newbie from Python and I am trying to grok alias. Is alias like Python does as below L = [] myextend = L.extend L.myextend Renaming imported function from itertools import permutations as p p([1, 2], 2) Is D aliasing the same as above? How does aliasing types help like below alias intList = LinkedList!int Is the above like a partially applied template as in LinkedList!int([1, 2, 3]) and hence can I use it like intList([1, 2, 3])? Adam D Ruppe was helping me on #d . I just thought posting to forum will have more people to discuss on this. Sorry for the double post.
What does alias do?
I am a D newbie from Python and I am trying to grok alias. Is alias like Python does as below L = [] myextend = L.extend L.myextend Renaming imported function from itertools import permutations as p p([1, 2], 2) Is D aliasing the same as above? How does aliasing types help like below alias intList = LinkedList!int Is the above like a partially applied template as in LinkedList!int([1, 2, 3]) and hence can I use it like intList([1, 2, 3])?
Re: Get the return type of the function
On Wednesday, 3 February 2016 at 19:21:06 UTC, Meta wrote: On Wednesday, 3 February 2016 at 18:40:27 UTC, xtreak wrote: Thanks. I was trying to get the return type of lambdas. I was trying the following and got an error. I was using dpaste with dmd 2.070 writeln(ReturnType!(a =(a *a))) Error: template instance f662.main.ReturnType!((a) => a * a) does not match template declaration ReturnType(func...) if (func.length == 1 && isCallable!func) Ah, I see. I'd like to test something; can you please change `(a) => a * a` to `(int a) => a * a` and post the results? Thanks for the reply. But the issue was about knowing the type of lambda in map. Most people won't enter the type of argument in a map. Is there a way to detect the return type will be non void. The return type is not much necessary here I just need to verify the function is not void.
Re: Get the return type of the function
On Wednesday, 3 February 2016 at 23:57:12 UTC, Ivan Kazmenko wrote: On Wednesday, 3 February 2016 at 22:09:37 UTC, sigod wrote: On Wednesday, 3 February 2016 at 19:21:06 UTC, Meta wrote: Ah, I see. I'd like to test something; can you please change `(a) => a * a` to `(int a) => a * a` and post the results? This works. http://dpaste.dzfl.pl/92c254ef6cf6 Seems reasonable: `(int a) => a * a` has return type `int` but just `(a) => a * a` does not yet know the type of `a`, and so can not tell the return type. Thanks for the reply. But the issue was about knowing the type of lambda in map. Most people won't enter the type of argument in a map. Is there a way to detect the return type will be non void. I don't need to know the type I just wanr to verify its not void. Yes * can be overloaded and can have different types based on the input having the overloaded operator implemented. I just want to check if the return type is not void.
Re: Get the return type of the function
On Thursday, 4 February 2016 at 05:50:05 UTC, tsbockman wrote: On Thursday, 4 February 2016 at 02:06:00 UTC, xtreak wrote: On Wednesday, 3 February 2016 at 23:57:12 UTC, Ivan Kazmenko wrote: [...] Thanks for the reply. But the issue was about knowing the type of lambda in map. Most people won't enter the type of argument in a map. Is there a way to detect the return type will be non void. I don't need to know the type I just wanr to verify its not void. Yes * can be overloaded and can have different types based on the input having the overloaded operator implemented. I just want to check if the return type is not void. See my PR for a workaround: https://github.com/D-Programming-Language/phobos/pull/3969/files Thanks a lot for the patch. It will be helpful if you could explain the workaround as I am a newbie in D language.
Get the return type of the function
I was reporting a patch for the regression by removing the code that was causing the error. The bug was that map was not accepting multiple lambdas. It was suggested to check for void functions and lambdas. I couldn't find a function to check for return type in the std.traits. I tried the explicit for loop thus checking for the void functions as in the else case. I am D newbie it will be helpful in having the community help me in fixing the issue. foreach(g, i; fun) { alias k = unaryFun!(fun[g]); static assert(!is(AppliedReturnType!k == void), "Mapping function must not return void."); } Bug report : https://issues.dlang.org/show_bug.cgi?id=15480 Seems depends on : https://issues.dlang.org/show_bug.cgi?id=5710 Pull request : https://github.com/D-Programming-Language/phobos/pull/3963 Introduced as a part of https://github.com/D-Programming-Language/phobos/pull/1917
Re: Get the return type of the function
On Wednesday, 3 February 2016 at 17:40:23 UTC, Meta wrote: On Wednesday, 3 February 2016 at 17:12:03 UTC, xtreak wrote: I was reporting a patch for the regression by removing the code that was causing the error. The bug was that map was not accepting multiple lambdas. It was suggested to check for void functions and lambdas. I couldn't find a function to check for return type in the std.traits. I tried the explicit for loop thus checking for the void functions as in the else case. I am D newbie it will be helpful in having the community help me in fixing the issue. foreach(g, i; fun) { alias k = unaryFun!(fun[g]); static assert(!is(AppliedReturnType!k == void), "Mapping function must not return void."); } Bug report : https://issues.dlang.org/show_bug.cgi?id=15480 Seems depends on : https://issues.dlang.org/show_bug.cgi?id=5710 Pull request : https://github.com/D-Programming-Language/phobos/pull/3963 Introduced as a part of https://github.com/D-Programming-Language/phobos/pull/1917 Unles I'm misunderstanding you, you can get the return type of a function by using std.traits.ReturnType: void test() {} static assert(is(ReturnType!test == void)); Thanks. I was trying to get the return type of lambdas. I was trying the following and got an error. I was using dpaste with dmd 2.070 writeln(ReturnType!(a =(a *a))) Error: template instance f662.main.ReturnType!((a) => a * a) does not match template declaration ReturnType(func...) if (func.length == 1 && isCallable!func)
Worker is not finished while sending message to intermediate worker
I am using programming in D to learn about D language. I wrote a simple program that spawns a worker and sends it a number to receive its square as a string. The worker 1 gets the number squares it and sends to worker 2 (a different function) to get casted as string which is returned to the worker 1 and thus it returns it to the main function call. I can write the whole thing in a single thread. I wrote it to understand about workers better. I used receive to get the worker 1 act as per the input. The program is as follows import std.stdio; import std.concurrency; import std.conv; import core.thread; void main() { foreach (int num; 1..100) { auto square_tid = spawn(square); square_tid.send(num); auto square = receiveOnly!string(); writeln(square); } } void square() { static i = 0; receive ( (int num) { auto square = num * num; writeln(sqaure : Comes in with , num , for , ++i , time); auto stringWorker = spawn(stringConverter); stringWorker.send(thisTid, square, ownerTid); }, (Tid tid, string str) { writeln(comes in string); send(tid, hello); }); } void stringConverter() { static i = 0; auto params = receiveOnly!(Tid, int, Tid)(); auto stringified = to!string(params[1]); // Stringify the square writeln(string : Comes in with , params[1], for , ++i , time); params[0].send(params[2], stringified); // params[0] - square function tid, // params[2] - main function tid } I got the answer from stackoverflow @ https://stackoverflow.com/questions/28128383/worker-is-not-finished-while-sending-message-to-intermediate-worker. But the person who answered my question asked me to post back to dlang learn to learn more about it. As I spawn the function and a send a message to stringConverter as it sends a message to the square function why do I need to embed another receive call inside the int case as indicated in the answer. How can I avoid embedding the receive call and why does the person in the second answer used while(1) to receive the message.
Re: Worker is not finished while sending message to intermediate worker
On Monday, 9 February 2015 at 20:11:09 UTC, Ali Çehreli wrote: On 02/09/2015 11:46 AM, Ali Çehreli wrote: threads normally start one [or] more worker threads and send tasks to those threads Accordingly, the following program uses just three threads: import std.stdio; import std.concurrency; import std.conv; import core.thread; struct Terminate {} void main() { auto square_tid = spawn(square); foreach (int num; 1..100) { square_tid.send(num); auto square = receiveOnly!string(); writeln(square); } square_tid.send(Terminate()); } void square() { auto i = 0; bool done = false; auto stringWorker = spawn(stringConverter, ownerTid); while (!done) { receive ( (Terminate message) { stringWorker.send(message); done = true; }, (int num) { auto square = num * num; writeln(sqaure : Comes in with , num , for , ++i , time); stringWorker.send(square); }); } } void stringConverter(Tid destination) { auto i = 0; bool done = false; while (!done) { receive ( (Terminate message) { done = true; }, (int num) { auto stringified = num.to!string; writeln(string : Comes in with , num, for , ++i , time); destination.send(stringified); }); } } Ali Hi Ali, Thanks for your book :) I am using it for learning D. I want the stringConverter to send a message to square which in turn messages the main function with string hello. So are you saying that message is not delivered to square from stringWorker. How does embedding the receive call inside the int in stackoverflow answer receives the message? It seems silly but how can I keep my threads alive to receive messages? Thanks a lot again. Please correct me if I am wrong anywhere.