Just reporting this to save other people some debugging time:
Hanna Codes unintentionally "memoize" results.
Here's a rough example of what I mean.
Imagine a stateful Hanna Code.
For example, imagine a Hanna Code that maintains a count, and increases the count each time it's used:
[[count]]
[[count]]
[[count]]
You'd expect this:
1
2
3
But you'll get this instead:
1
1
1
Here's where it gets very odd though: your Hanna Code will in fact be called three times, and the counter will in fact end up at "3"!
It took me a bit to figure out what was going on.
The problem is that all Hanna Codes are extracted up front, here. Then they're processed one by one, here. As each Hanna Code is processed, it gets replaced here. And that's the problem: the replacement is global; all matches get replaced, not just the first.
So in this example all three `[[count]]`s will be extracted, and the loop will iterate three times, but the first iteration will replace all occurrences of `[[count]]`, leaving nothing for the next two iterations to replace.
(I'm calling this "unintentional memoization" because typically you memoize to avoid work. In this case work isn't avoided, the result of the work simply isn't used.)