<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 5.50.4134.100" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>> Heiko wrote:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Courier size=2>> SETUP = object()<BR>> ELSE =
object()<BR>> BREAK = object()</FONT></DIV>
<DIV><FONT face=Courier size=2>> </FONT></DIV>
<DIV><FONT face=Courier size=2>> machine = {"WAITING FOR ACTION":<BR>>
{customer_drops_coin:"COIN HAS BEEN DROPPED",<BR>>
customer_selects_beverage:"ORDER RECEIVED",<BR>>
customer_cancels_order:"ACCOUNT CLOSURE IS DUE"<BR>>
ELSE:"WAITING FOR ACTION"},<BR>>
"COIN HAS BEEN
DROPPED":<BR>>
{SETUP:identify_coin,<BR>>
credit_account:"PAYMENT DUE IS UNKNOWN"},<BR>>
"ORDER
RECEIVED":<BR>>
{...</FONT></DIV>
<DIV><FONT face=Arial size=2>></FONT></DIV>
<DIV><FONT face=Arial size=2>> Reading the state machine in the way presented
above isn't any harder in my<BR>> taste than reading your state table, and
you should easily be able to run the </FONT><FONT face=Arial size=2><BR>>
machine from there...</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>> --- Heiko.<BR></FONT></DIV>
<DIV><FONT face=Arial size=2>I think I get your idea. I also see a few problems
with your proposal. Let me try:</FONT><FONT face=Arial size=2></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Courier size=2>def </FONT><FONT face=Courier
size=2>customer_drops_coin (): ...</FONT></DIV>
<DIV>
<DIV><FONT face=Courier size=2>def customer_selects_beverage ():
...</FONT></DIV>
<DIV><FONT face=Courier size=2>def customer_cancels_order: ...</FONT></DIV>
<DIV><FONT face=Courier size=2>etc.</FONT></DIV></DIV>
<DIV><FONT size=2>
<DIV><FONT face=Courier></FONT> </DIV>
<DIV><FONT face=Courier>def ELSE: return True</FONT></DIV>
<DIV><FONT face=Courier size=2></FONT> </DIV>
<DIV><FONT face=Courier size=2></FONT> </DIV>
<DIV><FONT face=Courier size=2>machine = </FONT><FONT face=Courier size=2>{
"WAITING FOR ACTION": ( (
customer_drops_coin, "COIN HAS BEEN
DROPPED"
),<BR>
( customer_selects_beverage, "ORDER RECEIVED"
),<BR>
( customer_cancels_order, "ACCOUNT CLOSURE IS DUE"
),<BR>
# (
ELSE,
"WAITING FOR ACTION"
),<BR>
),</FONT></DIV>
<DIV><FONT face=Courier size=2></FONT> </DIV>
<DIV><FONT face=Courier
size=2> "COIN
HAS BEEN DROPPED": ( (
identify_coin, None ),<BR>
(
credit_account,
"PAYMENT DUE IS UNKNOWN" ),<BR><FONT
face=Arial>
),</FONT></DIV></FONT>
<DIV><FONT face=Courier size=2></FONT> </DIV>
<DIV><FONT face=Courier
size=2> "ORDER
RECEIVED":<BR>
( ( ...</FONT></DIV></FONT></DIV>
<DIV><FONT face=Courier size=2> </FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial><FONT size=2> <FONT face=Courier size=2>def
run_state_machine (machine, initial_state = "BEGIN"):</FONT></DIV>
<DIV>
<DIV><FONT face=Courier></FONT> </DIV>
<DIV><FONT face=Courier> state = initial_state # Here
would be "WAITING FOR ACTION"</FONT></DIV>
<DIV><FONT face=Courier> while True:</FONT></DIV>
<DIV><FONT face=Courier> for function,
next_state in machine [state]:</FONT></DIV>
<DIV><FONT face=Courier> go_next
= function ()</FONT></DIV>
<DIV><FONT face=Courier> if
go_next:</FONT></DIV>
<DIV><FONT
face=Courier>
if next_state:</FONT></DIV>
<DIV>
<FONT face=Courier> state = next_state</FONT><FONT
face=Courier></FONT></DIV>
<DIV><FONT face=Courier> if
state == "END":</FONT></DIV>
<DIV><FONT face=Courier>
return</FONT></DIV>
<DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>This should work.</FONT></DIV>
<DIV> </DIV>
<DIV>Frederic</DIV>
<DIV> </DIV></DIV></FONT></DIV></FONT></BODY></HTML>