Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Passing the new arguments in as the return value of the yield is the only way that makes sense to me. Rebinding the original arguments might be very far removed from the yield statement (the coroutine might have started in one block of code, but the yield might be the n'th sub child, where the original arguments are totally inaccessible and will not be accessible until all of the nested subs have finished yielding partial results and have returned back to the the grandparent code that actually has access to
    • Additionally, it makes sense that the argument list for "start a new sequence" is different from "continue to find the next sequence element". The first argument list will contain arguments that are global to the entire sequence; while the second will be more local in meaning. The canonical coroutine example is a walker for a binary tree. The call that starts walking the tree might have an argument that chooses pre-order, in-order, or post-order traversal. That argument would not make sense for one of t
    • Hmm, maybe the ongoing subroutine needs a & method that simply resumes the yield, and then calling &coro(args) will pass args as yield's return value, just as you and iblech had argued for. Rebinding can then take place if the user asks for it, with an is rebound trait. What do you think of this?
      • Having both a functional and object interface to a coroutine is a separate issue. In the functional interface, if you don't have anything to pass as the return value from the yield, just pass nothing. So, &coro(args) will cause the yield to return (args) and &coro() has it return nothing. No need for a method to distinguish. Generally, I think that whenever you look to rebind the initialization arguments, you'd generally prefer to start a separate coroutine instance with different initialization