Re: stackless proposal (from WIKI)
"Mark Hahn" <[email protected]>
| Newsgroups | gmane.comp.lang.prothon.user |
|---|---|
| Message-ID | <[email protected]> |
Lenard wrote: > Sure. If there were some way to tie this "coupler" into a generator > then the "yield" keyword can go away. Maybe creating a generator > instance > causes a "yield" coupler object to be created that is accessed through > the call stack: > > <verbatim> > thread fib(n): > sum, prev = 1, 0 > for i in n: > caller.yield.send(sum) > sum, prev = sum + prev, sum > </verbatim> > ---- > Mark: > The purpose of a coupler is to allow one thread to switch to another > thread by connecting them together, but a generator only involves one > thread calling another in a restartable way. I don't think a coupler > would be involved with a generator. The yield operation is specific > to a generator and I don't see any problem keeping it the way it is. It has taken a week for it to sink into my thick skull, but I finally realized that you are correct. A generator with a yield statement is exactly the same same as co-routines where the next() call is mating up with the yield statement like two channel.transfer() calls. I have expanded your idea into a full proposal for how to do the stackless language implementation using your thread and yield keywords. I'll put it up on the Wiki.