I've implemented a state machine using functions. Calling a function indicates an event, and causes actions that change the state. Each function includes as condition a specific state, so that the function is only be executed in a specific state -- all shown below. Oddly, the function F1 is executed twice, the first time when S is 1, and then when during the execution of actions the state is set to 2 (S=2), the function is executed again, and S is set to 3, even though the client only made one call.
This is rather intuitive behavior, at least to me. Am I misunderstanding how function calls work?
F1/S=1 => Action 1, Action 2, S=2
F1/S=2=> Action 3, Action 4, S=3
Event -> S=1, F1