[Prev][Next][Index][Thread]

Re: Multiply-keyed collection classes



neelk@brick.cswv.com (Neel Krishnaswami) writes:

> It's actually the transition table for the state machine that I'm
> looking to represent as a collection. Since it's a finite function

I usually implement state machines using singleton dispatch:

define method state-transition(state == #"foo", input == #"23")
  #"bar";
end;

define method state-transition(state == #"bar", input == #"42")
  #"foo";
end;

define method state-transition(state, input)
  error("Illegal input");
end;

while(there-is-input)
  state := state-transition(state, get-input());
end;

The benefit is that you have a well-defined place where you can put
your code to execute on transition. The downside is that you have no
explicit transition table (although you still can modify the generic
function at runtime).

Andreas

-- 
"Anyone need a DVD decrypter for Linux?
dig @138.195.138.195 goret.org. axfr | grep '^c..\..*A' | sort \
| cut -b5-36 | perl -e 'while(<>){print pack("H32",$_)}' | gzip -d"
  -- James Brister



Follow-Ups: References: