Stackless resumable functions

ketmar via Digitalmars-d digitalmars-d at puremagic.com
Sun Feb 22 18:00:34 PST 2015


On Mon, 23 Feb 2015 00:48:42 +0000, bitwise wrote:

> I don't like the idea of having a resumable function look like a regular
> delegate. There would be no clean way to check when the resumable
> function had finished.

you don't need to. if you really need to do that, you're doing something 
wrong trying to recreate ranges and exposing their internal design to the 
user. this resumable function *is* delegate. nobody cares about it's 
internals.

> I've only skimmed the C++ proposal for resumable
> lambdas below, but it seems like their solution is to introduce a
> 'stop_iteration' exception which gets thrown when you try to call a
> resumable lambda that has run to completion. So basically, all uses of
> delegates would have to be wrapped in try/catch blocks..

resumable functions are not iterators. it's a slightly perversed flow 
control method. iteration/generation is one of the use cases.

and, by the way, yielding is a two-way communication channel.

you seem to stuck with iteration/generation idea, but this is not the way 
resumable functions should be seen. resumable functions are basics of 
cooperative multitasking, and iteration/generation is just a special case 
of coop mt.

mimicking delegates allows to use resumable function in any code that 
expects delegate. and defining interfaces (yeilding is two-way comm 
channel!) will allow to build generator abstraction a-la range (or even 
mimicking any necessary range).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20150223/431d7622/attachment.sig>


More information about the Digitalmars-d mailing list