How is defer timed with recursive calls?

My code for a loop-less sequence-on-filter-sequence method required me to add a do-block to prevent infinite recursion. It seems that if a return path involves a (tail?) recursive call, then outstanding defer blocks don't trigger until the recursive call finishes. Since my code needed the increment(s) to happen before the recursion, I added the do structuring.

Am I understanding it correctly?

That sounds correct. defer happens "at the return (or break or continue)" or "at the close brace", and that means after any recursive calls to compute the value to return.

Terms of Service

Privacy Policy

Cookie Policy