Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Are state machines just for parsing?

by dragonchild (Archbishop)
on Dec 08, 2004 at 13:20 UTC ( #413189=note: print w/replies, xml ) Need Help??

in reply to Are state machines just for parsing?

What kind of interface / API would you be interested in seeing? How would you want to use said module?

The reason I ask is that I've built state machines for several projects and they were different enough that I don't think I could've used a generic solution / framework. For example, I've used state machines to

  • perform actions in a basic scripting language
  • handle events that have been defined to fire when X occurs
  • be the engine for a web application (both before I found CGI::Application and with it)

It's kinda like trying to build a module for the Schwartzian Transform or the Guttman-Rosler Transform (GRT). It's good to know the pattern, but making a generic version just complicates the matter. Or, put another way, we'd almost have to write another mini-language to have a state machine. And, we already have that with regexes.

Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

  • Comment on Re: Are state machines just for parsing?

Replies are listed 'Best First'.
Re^2: Are state machines just for parsing?
by samtregar (Abbot) on Dec 08, 2004 at 22:15 UTC
    What kind of interface / API would you be interested in seeing?

    I see two phases. First, I need an API to lay out the network. For my purposes each state has to have:

    • A unique name
    • A description
    • A list of possible next states
    • Code which runs when the state is reached
    • Code to determine if this state should be the next one

    I don't know what this API should look like. Maybe each state is a Perl module implementing a few methods. Maybe it's just a big data structure made of hashes and arrays. Whatever it is it has to be easy to change later when the businessmen change their minds.

    Next I need to give the machine a starting state and an event. The machine should either tell me what the next state is or produce an error if the event doesn't trigger a valid next state. Something like:

    $next_state = $machine->run($state, $event);


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://413189]
[ambrus]: Corion: push_write is in the higher level abstraction of AnyEvent::Handle, not in the watcher
[Corion]: ambrus: Hmm - rereading Prima::File, that merrily coincides with what Prima does - it tells you "you can read", and you're supposed to read from the fh yourself. I thought it called you with the data already read, which would've been harder to integrate
[ambrus]: you just need an io watcher, created by &AnyEvent::Impl:: Whatever::io(...)
[Corion]: So after talking it through with you even while I'm still not entirely clear on where AE ends and my implementation begins, I think I understand that I only need to implement some smaller parts for each functionality I want to support.
[Corion]: Yeah... and you might even be able to mix and match additional functionality if you have additional async suppliers, like from a separate thread
[ambrus]: You hvae to be careful with the timer, because apparently Prima::Timer insists on being periodic, wheras AnyEvent::Impl:: Whatever::timer should give a one-shot timer watcher
[ambrus]: I think the minimal implementation here is just a timer and io function, plus pushing to the @REGISTRY.

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2016-12-08 12:23 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (141 votes). Check out past polls.