Popular recipes by Stefan Tunsch http://code.activestate.com/recipes/users/4178042/2011-05-20T13:46:48-07:00ActiveState Code RecipesRecursive Functional State Machine (Python)
2011-05-20T13:46:48-07:00Stefan Tunschhttp://code.activestate.com/recipes/users/4178042/http://code.activestate.com/recipes/577709-recursive-functional-state-machine/
<p style="color: grey">
Python
recipe 577709
by <a href="/recipes/users/4178042/">Stefan Tunsch</a>
(<a href="/recipes/tags/functional/">functional</a>, <a href="/recipes/tags/recursion/">recursion</a>, <a href="/recipes/tags/state_machine/">state_machine</a>).
</p>
<p>This is a simple state machine that takes a functional approach.
It requires trampoline from pysistence.func to avoid the recursion limit.</p>
<p>Namedtuples are used to define the different states.
globals() is used to reference the states. (This could also be done putting states into a separate module and getting them through getattr.)</p>
<p>In this recipe the functions called in the different states need to return a boolean, which defines the success or failure event.</p>