Re: Yield from function?

2017-01-31 Thread Ivan Kazmenko via Digitalmars-d-learn
On Monday, 30 January 2017 at 11:03:52 UTC, Profile Anaysis wrote: I need to yield from a complex recursive function too allow visualizing what it is doing. e.g., if it is a tree searching algorithm, I'd like to yield for each node so that the current state can be shown visually. I realize

Re: Yield from function?

2017-01-31 Thread Profile Anaysis via Digitalmars-d-learn
On Tuesday, 31 January 2017 at 11:31:28 UTC, Ali Çehreli wrote: On 01/31/2017 03:00 AM, Profile Anaysis wrote: > [...] [...] > [...] return type. Options: [...] Thanks again!

Re: Yield from function?

2017-01-31 Thread Ali Çehreli via Digitalmars-d-learn
On 01/31/2017 03:00 AM, Profile Anaysis wrote: > Just curious, how can I use start() recursively? [...] > Seems I can't create start with a parameter and non-void return type. Options: - The class can maintain state - You can start the fiber with a delegate; int local; double state;

Re: Yield from function?

2017-01-31 Thread Profile Anaysis via Digitalmars-d-learn
On Tuesday, 31 January 2017 at 06:32:02 UTC, Ali Çehreli wrote: On 01/30/2017 08:12 PM, Profile Anaysis wrote: import std.stdio, std.concurrency, core.thread; class Search : Fiber { this() { super(); } int res = 0; void start() { Fiber.yield(); res = 1; } }

Re: Yield from function?

2017-01-31 Thread Profile Anaysis via Digitalmars-d-learn
On Tuesday, 31 January 2017 at 06:32:02 UTC, Ali Çehreli wrote: On 01/30/2017 08:12 PM, Profile Anaysis wrote: [...] That's because the fiber is not in a callable state. (You can check with search.state.) Here is one where the fiber function lives (too) long: import std.stdio,

Re: Yield from function?

2017-01-30 Thread Ali Çehreli via Digitalmars-d-learn
On 01/30/2017 08:12 PM, Profile Anaysis wrote: import std.stdio, std.concurrency, core.thread; class Search : Fiber { this() { super(); } int res = 0; void start() { Fiber.yield(); res = 1; } } void main() { auto search = new Search(); search.call();

Re: Yield from function?

2017-01-30 Thread Profile Anaysis via Digitalmars-d-learn
On Monday, 30 January 2017 at 18:48:10 UTC, Ali Çehreli wrote: On 01/30/2017 03:03 AM, Profile Anaysis wrote: > I need to yield from a complex recursive function too allow visualizing > what it is doing. > > e.g., if it is a tree searching algorithm, I'd like to yield for each > node so that the

Re: Yield from function?

2017-01-30 Thread Profile Anaysis via Digitalmars-d-learn
On Monday, 30 January 2017 at 22:34:11 UTC, TheFlyingFiddle wrote: On Monday, 30 January 2017 at 11:03:52 UTC, Profile Anaysis wrote: I need to yield from a complex recursive function too allow visualizing what it is doing. e.g., if it is a tree searching algorithm, I'd like to yield for

Re: Yield from function?

2017-01-30 Thread TheFlyingFiddle via Digitalmars-d-learn
On Monday, 30 January 2017 at 11:03:52 UTC, Profile Anaysis wrote: I need to yield from a complex recursive function too allow visualizing what it is doing. e.g., if it is a tree searching algorithm, I'd like to yield for each node so that the current state can be shown visually. I realize

Re: Yield from function?

2017-01-30 Thread Ali Çehreli via Digitalmars-d-learn
On 01/30/2017 02:04 PM, cym13 wrote: On Monday, 30 January 2017 at 18:48:10 UTC, Ali Çehreli wrote: http://ddili.org/ders/d.en/fibers.html BTW the alias to avoid a name conflic on "Generator" isn't necessary anymore [...] Otherwise I believe you'll agree that removing it would make it

Re: Yield from function?

2017-01-30 Thread cym13 via Digitalmars-d-learn
On Monday, 30 January 2017 at 18:48:10 UTC, Ali Çehreli wrote: On 01/30/2017 03:03 AM, Profile Anaysis wrote: > I need to yield from a complex recursive function too allow visualizing > what it is doing. > > e.g., if it is a tree searching algorithm, I'd like to yield for each > node so that the

Re: Yield from function?

2017-01-30 Thread Ali Çehreli via Digitalmars-d-learn
On 01/30/2017 03:03 AM, Profile Anaysis wrote: > I need to yield from a complex recursive function too allow visualizing > what it is doing. > > e.g., if it is a tree searching algorithm, I'd like to yield for each > node so that the current state can be shown visually. I used tree iteration as

Re: Yield from function?

2017-01-30 Thread pineapple via Digitalmars-d-learn
On Monday, 30 January 2017 at 11:03:52 UTC, Profile Anaysis wrote: I need to yield from a complex recursive function too allow visualizing what it is doing. e.g., if it is a tree searching algorithm, I'd like to yield for each node so that the current state can be shown visually. I realize

Yield from function?

2017-01-30 Thread Profile Anaysis via Digitalmars-d-learn
I need to yield from a complex recursive function too allow visualizing what it is doing. e.g., if it is a tree searching algorithm, I'd like to yield for each node so that the current state can be shown visually. I realize that there are several ways to do this but D a yield version