Uh oh!
There was an error while loading. Please reload this page.
Coroutines - #53
Conversation
There was a problem hiding this comment.
@thestinger confused me a bit about the subject, but my last findings suggest Python is misusing the word "coroutines", which traditionally are a superset of "generators" (the difference being the ability to yield through multiple stack frames).
There was a problem hiding this comment.
True, that's why I called them "shallow" coroutines.
eddyb
commented
Apr 25, 2014
I would much rather see all the tools required for implementing this (in a syntax extension, for example), than baking it into the language (like closures are today, and will be before you can implement |
vadimcn
commented
Apr 25, 2014
I think you'd need some kind of "unsafe goto", which is ignored by borrow/lifetime checker passes for this to be possible as a syntax extension. Not likely, in my estimation... |
eddyb
commented
Apr 25, 2014
Why? When you can do a state machine transform and you get code that's easier to optimize. |
vadimcn
commented
Apr 25, 2014
@eddyb, I would love to see how that transform looks like! |
eevee
commented
May 4, 2014
Based on my experience with Python:
|
vadimcn
commented
May 5, 2014
Assuming the coroutine->iterator "adapter" trait is provided by the standard library (as it should), your collection iterator implementation will look like this:
We could support that, but what would that save us vs the above? A pair of braces? (presumably, you'd still have to say
Quite the opposite, actually. This is where being wrapped in an outer function comes in handy: The initial set of arguments go to the outer function, which may perform some pre-processing, before constructing and returning the coroutine closure. |
alexcrichton
commented
Jun 12, 2014
Thanks for the RFC! The team has decided that while desirable, this is not needed for 1.0 at this time. I imagine that a library such as this will work best with as little language support as possible, so this may be best done as a new library rather than a language change per-se. Closing. |
vadimcn
commented
Jun 12, 2014
:( Did the team have concrete suggestions of how this could be done as a library? |
alexcrichton
commented
Jun 13, 2014
We believe that it's possible to add support for this in a backwards-compatible fashion, especially because |
flying-sheep
commented
Jul 9, 2014
how should that be possible?
this needs first-class support of pauseable and resumable code. |
pnkfelix
commented
Jul 9, 2014
I think what Alex means is that a library in stdlib could provide the functionality. This is analogous to how (Caveat: I have not given any consideration to how the borrow-checking rules could be impacted by such a feature. I am assuming it's a solvable problem at worst.) |
flying-sheep
commented
Jul 10, 2014
ok, this is sadly far over my head. the implications and techniques necessary to create a data structure wrapping a function’s environment and stack is too deep to consider working on. i hope some heavy contributor takes this up. |
Rendered