On Dec 15, 2004, at 3:56 PM, Paul Hoffman wrote:

It seems to me that your code could be used to implement either
a DFA or an NFA, so you might want to call it it an FSM.
Algorithm::FSM, perhaps?  Or maybe Decision::FSM??

I went with FSM::Rules. I think it's a good name, and falls in line, I think, with your suggestions.


In essence, you've written DFA::StateMachine to use a "pull"
model in which the code that checks what to do next "fetches"
the input itself, where I would generally want to use a "push"
model in which the driver code takes care of that.  They're
effectively equivalent, it just might be more straightforward to
use a push model, especially if your program is dealing with
input that's awkward to "unpull" such as file I/O.

The nice thing is, easy to use a push-oriented API in a pull
kind of way; just don't feed the DFA any input (C<$dfa->process>
rather than C<$dfa->process($input)>) and write your "goto"
closures so they don't expect to get any input.

That's a good idea. I think I'll add that to the C<try_switch()> method (which is what I ended up renaming from C<check()>). Really simple. Look for it in 0.05 in a bit.


BTW, I really like how your implementation avoids polluting the
object with special elements (e.g., $self->{__states__} or some
such) by keying the states off the stringified object.  Nice!

Thanks! I just wanted it to be an empty hash that the states could stash stuff into. Makes it easier to subclass, too.


You might want to factor out some common subexpressions,
C<$states{$self}> in particular.  That's a bit nitpicky --
premature optimization yadda yadda -- but in some places it
would make the code easier to read.

Yeah. That's low-ish on my priority list, though.

If you like my ideas but you're short on time, let me know; I
might be able to whip up a patch.

Paul.

P.S.: You could implement DFA::StateMachine::done() by setting
the done flag in $states{$self}->{done} or simply undef'ing
$states{$self}->{current}.

You're a mind reader. Ovid suggested the same thing to me, and it's now in 0.04 (making its way to CPAN). He even suggested the same name! It can optionally be a code reference, too, which makes it potentially more convenient.


Regards,

David



Reply via email to