<br><br><div><span class="gmail_quote">On 3/20/06, <b class="gmail_sendername">Richard Cameron</b> <<a href="mailto:camster@citeulike.org">camster@citeulike.org</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>On 20 Mar 2006, at 13:43, Serge Aleynikov wrote:<br><br>> I wonder if someone could share their experience at dealing with<br>> large FSMs. We are in the midst of implementing an FSM which<br>> logically can be broken down in two groups of states. It would be
<br>> good to be able to split these states among two separate modules,<br>> but gen_fsm doesn't allow to do this easily.<br><br>I always seem end up writing large FSMs as special processes (<http://<br><a href="http://erlang.se/doc/doc-5.4.12/doc/design_principles/spec_proc.html">
erlang.se/doc/doc-5.4.12/doc/design_principles/spec_proc.html</a>>) and<br>simply doing things the old fashioned pure Erlang way:<br><br>state1() -><br> receive<br> go_to_state_2 -> state2();
<br> _ -> state1()<br> end.<br><br>state2() -><br> receive<br> go_to_state_1 -> state1();<br> go_to_state_3 -> state2()<br> end.<br><br>...<br>
<br>Something like that would let you split the states over multiple<br>modules (assuming you can keep a mental image of the maze of cross-<br>module calls in your head).<br><br>The problem always find I have with gen_fsm is that events need to be
<br>dealt with immediately. You've got the option to either pattern match<br>with a "don't care" variable to simply ignore an event if it occurs<br>when you don't want it, or you can have the FSM abnormally. What you
<br>can't do is queue the event up to be dealt with when the FSM moves<br>into a more appropriate state.<br><br>I generally find that I want precisely this behaviour in at least one<br>of my states (and this becomes more likely the bigger the FSM is). As
<br>Erlang's syntax is almost ideal of writing FSMs anyway, I just don't<br>find gen_fsm adding much (other than taking care of OTP system<br>messages automatically.).<br><br>Richard.<br></blockquote></div><br>
Wouldn't this cause the stack to bloat indefinitely? Or does tail-calling eliminate this in Erlang?<br>