continue in catch block? seperate interaction with widgets and work flow

Bill Baxter dnewsgroup at billbaxter.com
Thu Oct 19 20:29:54 PDT 2006


Daniel Keep wrote:
> 
> Bill Baxter wrote:
> 
>> sounds kind of similar to generators & coroutines for which the keyword
>> "yield" is often used.  "Green threads" is another related term.
 >> [...]
>>
>> --bb
> 
> Disclaimer: Big fan of both Python, Stackless, and this sort of stuff in
> general.  May be just a *wee* bit biased :P
> 
> *ahem*
> 
> There are many ways in which coroutines / green threads / generators /
> tasklets / etc. can make life easier.  Here's a few I can think of off
> the top of my head:

Thanks Daniel for the excellent explanation.  All that does make sense 
to me now.

> 1. State machines.

I had heard "state machines" were a good use before, somehow the 
explanation I read didn't make sense to me.  Yours did.

> 2. Pipelines
> 
> With coroutines and channels, you can write the components like so:
> 
> void invert(Channel input_channel, Channel output_channel)
> {
>     while( input_channel.available
>         && input_channel.connected
>         && output_channel.connected )
>     {
>         auto pixel = input_channel.receive();
>         pixel.r = 1.0 - pixel.r;
>         pixel.g = 1.0 - pixel.g;
>         pixel.b = 1.0 - pixel.b;
>         output_channel.send(pixel);
>     }
> }
> 

So I take it that allows you to write code like:
    image.invert().grayscale().auto_contrast().threshold()
Where each pixel is processed one-by-one rather than creating big 
memory-hogging tmp images as the output for every stage.  That is nice. 
    I remember searching for some way to do this kind of stream 
processing back in my early days with C and being surprised that there 
wasn't.  Especially surprising since like you say Unix is all about 
pipes and chaining things together, and Unix and C go hand in hand.


> 
> 3. Concurrency
> 

I can see it makes code simpler, but "single threaded" concurrency seems 
kinda a bad direction to be heading when 64 core processors are right on 
the horizon.

> 
> 4. Generators
> 

This one made sense to me before.

So is there any reason D couldn't work with coroutines?  It just needs 
to manage the stack in a slightly more tricky way, basically, right?

--bb



More information about the Digitalmars-d mailing list