-
Notifications
You must be signed in to change notification settings - Fork 560
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
Flipflop under recursion #14110
Comments
From @cpansproutperlop.pod states: Each ".." operator While that is true and well-known, what few know is that recursive calls to the containing subroutine do not share that boolean state with the outer call. What’s weirder is that each recursion level maintains its own state. So, for instance, if you have a function calling itself recursively to the fifth level, the flip-flop operator evaluated at that level will not use the same state again until that function is called to that level again. I haven’t come up with an example of this weird behaviour yet, but I’ll try to post something in the next day or two. My question is: Is this behaviour intentional? It doesn’t match my reading of the documentation. And I can’t think of any use for it short of obfuscation. I am inclined to think this is a bug. Further, I have found a discrepancy in this operator, in that it returns the same scalar each time when the enclosing sub is not called recursively, but a different scalar each time when the enclosing sub *is* called recursively. I was about to fix that discrepancy, when I realised that sharing the state between recursion levels would make the fix easier (the same change would fix both). -- Father Chrysostomos |
From @janduboisOn Mon, Sep 22, 2014 at 6:13 PM, Father Chrysostomos
I don't actually know how this works, but I assume the observed Cheers, |
The RT System itself - Status changed from 'new' to 'open' |
From @cpansproutOn Mon Sep 22 18:19:26 2014, jdb wrote:
Your assumption is correct.
I was thinking of having the same SV in the recursive pads, just as we do for constants under threads. -- Father Chrysostomos |
From @cpansproutOn Mon Sep 22 18:26:08 2014, sprout wrote:
And by making the pad code treat them like constants, I thought I could avoid special cases. But that would cause closures to share state, whereas currently they don’t, and that could have serious consequences for backward-compatibility. So it looks as though I have to special-case flip targets regardless. -- Father Chrysostomos |
From @cpansproutOn Mon Sep 22 18:13:16 2014, sprout wrote:
I went ahead and fixed that discrepancy in commit 14d9114 without touching the recursion issue. -- Father Chrysostomos |
From @cpansproutOn Mon Sep 22 18:13:16 2014, sprout wrote:
s/day/month/ :-) # This routine maintains multiple flip-flop states, each with its own for(1..20) { The output is: 3 3 Now how much code is depending on that bug? None, I would imagine. And if someone wanted to write something like the above, an array of closures would be a more straightforward way to do it. After all, the higher the ID, the slower the flip-flop function. -- Father Chrysostomos |
From @cpansproutOn Mon Sep 22 18:13:16 2014, sprout wrote:
Fixed in 00e4076. -- Father Chrysostomos |
@cpansprout - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#122829 (status was 'resolved')
Searchable as RT122829$
The text was updated successfully, but these errors were encountered: