go ahead... be a heretic | |
PerlMonks |
Re: Re: Perl 6 coroutines (RFC 31)by John M. Dlugosz (Monsignor) |
on Jul 13, 2001 at 18:23 UTC ( [id://96406]=note: print w/replies, xml ) | Need Help?? |
Yea, I know each has a similar problem, but it's not as bad because it has a separate state per hash. Called code can iterate over a different hash without messing it up. Likewise, readdir is given a handle, and you can have multiple handles open. It's no different from a normal file read, really. m//g is even better, in that not only is it per string (and a string can be copied to a local temp so nobody else will even try to iterate over the same copy), but you can use pos() to reset the state, or cancel it by matching a RE without a /g. How is any of that "*exactly* the same"? My issue with the proposal is that the iterator would be global for all instances. It would be like each maintaining a single global state, rather than per-hash. IAC, Perl 6 will fix nested each's on the same collection.
but more to the point, coroutine like behaviour only happens when yield is used. In the example you present, no yield happens, so it will behave like any other subroutineWhy do you say that? next_inorder() yeilds. there is of course return ah, that makes sence. You can't pass parameters into the iteration in-progress, but you could have a separate reset function that sets a shared global and calls the iterator, which sees the flag and returns. —John
In Section
Meditations
|
|