Cat FSM
As a continuation of my previous post about the chapter Rage Against The Finite-State Machines from Learn You Some Erlang for Great Good here is a gen_fsm
implementation for the Cat’s FSM described in the chapter.
This is a primitive one-state FSM, but the difference is that synchronous calls are used.
The output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
27> c(cat_fsm).
{ok,cat_fsm}
28> cat_fsm:test().
Switching to 'dont_give_crap' state
<0.145.0>
Cat replied: ok
Switching to 'dont_give_crap' state
Cat replied: ok
Switching to 'dont_give_crap' state
Cat replied: ok
Cat receives an unknown global sync event: hello
Cat receives an unknown global event: how_are_you
terminating with reason normal at state dont_give_crap
29>
December 15, 2011 | | Tagged erlang