New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix each() to be attached to the operator, not the data #142
Comments
This should be trivial, he said with the air of man about to try something really difficult. I see two cases to deal with: |
No, I don't think it does. You should be able to just catch the keyword, replace it with "perl5i::2::safe_each Problem is, I don't think Devel::Declare will pick up a keyword. |
Ah, because it picks up keywords that haven't been defined yet. Yes, I think I remember something about that as well. Maybe the Pluggable Keywords will allow it. Must spend some time investigating this. |
Ah, |
Stumbling block: |
I'd say change
and the same hash ref is passed to it twice. The second time through it will have an unreset iterator. Its a shame there can't be an implied reset before the loop, I think that requires making too many assumptions. I don't like %h->each(ID) because how do you pick an ID that isn't going to clash with someone else? And its ugly. I like your idea of using the file and line number better. Its also worth considering that the major use case for I think what |
One of
This relies on being able to use the same iterator for both of the Perhaps we could return the iterator number in list context:
|
I think we should split the use cases. An iterator associated with the data structure for doing Clever Things and one that's associated with the data + call for Mere Mortals. |
Here is a proof of concept. There are at least three problems with it: we have to use edit: minor fix to use
|
After using jQuery, thinking about subroutine signatures and seeing the complexity of fixing each() I think this will be much better served by a method with a callback.
Its simple and clear. We just need anonymous functions with signatures which are on the way. |
That should do it, I'm going to call this done. |
each() is dangerous because the iterator is attached to the data being operated on. For example...
Both calls to each() share the same iterator. They should not. The iterator should be attached to the operator. How do you do this? One possibility is to use Devel::Declare to replace "each %hash" with "safe_each 1234, %hash" where 1234 is a unique identifier for that call to safe each. The iterator is stored by %hash->mo->id and each ident.
The text was updated successfully, but these errors were encountered: