> Heiko wrote:
 
> SETUP = object()
> ELSE = object()
> BREAK = object()
>
> machine = {"WAITING FOR ACTION":
>               {customer_drops_coin:"COIN HAS BEEN DROPPED",
>                customer_selects_beverage:"ORDER RECEIVED",
>                customer_cancels_order:"ACCOUNT CLOSURE IS DUE"
>                ELSE:"WAITING FOR ACTION"},
>            "COIN HAS BEEN DROPPED":
>                {SETUP:identify_coin,
>                 credit_account:"PAYMENT DUE IS UNKNOWN"},
>             "ORDER RECEIVED":
>                {...
>
> Reading the state machine in the way presented above isn't any harder in my
> taste than reading your state table, and you should easily be able to run the

> machine from there...
 
> --- Heiko.
I think I get your idea. I also see a few problems with your proposal. Let me try:
 
def customer_drops_coin (): ...
def customer_selects_beverage (): ...
def customer_cancels_order: ...
etc.
 
def ELSE: return True
 
 
machine = { "WAITING FOR ACTION":    ( ( customer_drops_coin,        "COIN HAS BEEN DROPPED" ),
                                       ( customer_selects_beverage,  "ORDER RECEIVED" ),
                                       ( customer_cancels_order,     "ACCOUNT CLOSURE IS DUE" ),
                                     # ( ELSE,                       "WAITING FOR ACTION" ),
                                     ),
 
            "COIN HAS BEEN DROPPED": ( ( identify_coin,              None ),
                                       ( credit_account,             "PAYMENT DUE IS UNKNOWN" ),
                                                                           ),
 
            "ORDER RECEIVED":
                                     ( ( ...
   
 
 def run_state_machine (machine, initial_state = "BEGIN"):
 
   state = initial_state   # Here would be "WAITING FOR ACTION"
   while True:
      for function, next_state in machine [state]:
         go_next = function ()
         if go_next:
            if next_state:
                           state = next_state
         if state == "END":
            return
 
This should work.
 
Frederic
 
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to