; From: Dat Thuc Nguyen
; URL: http://www.smalltickle.com
;
; The state machine is a useful concept in many applications.
; The following script suggests a framework for a state machine.
;
; Replace the ECHO statements with the desired functionality
; for each state.  Note that normally an "input" would be
; provided as an argument to each state_xxxx macro to allow it
; to decide whether to change state, and which state to change to.

define state_initial {
    echo This is the \m(state) state.
    .state = warmup
    echo The next state is \m(state).
}

define state_warmup {
    echo This is the \m(state) state.
    .state = running
    echo The next state is \m(state).
}

define state_running {
    echo This is the \m(state) state.
    .state = slowdown
    echo The next state is \m(state).
}

define state_slowdown {
    echo This is the \m(state) state.
    .state = stop
    echo The next state is \m(state).
}

.state = initial
while not equal \m(state) stop { state_\m(state) }

END
