Here's one way to do implement a simple state machine like this in Scheme, with a procedure representing a state, and using tail calls (function calls that don't return) for the transitions:
In Scheme you could also decide on your state model, and make the code more maintainable in terms of that state model, by defining a minilanguage or domain-specific language for it: