Philip Newton (pne) wrote,
Philip Newton
pne

  • Mood:

Finite State Machine

At work, I was recently asked to write a little subroutine in BODI script to determine whether a given string is a number or not, since we had a job that occasionally died on us and J suspected that the many database hits caused by the current function were the culprit.

I decided to implement it as a finite state machine, mostly because (a) BODI script doesn't have regex capabilities (in fact, it has very few capabilities at all) and (b) I had seen it done that way elsewhere at some point and thought it was nifty.

I drew up a little state-transition diagram on paper first to guide me; here it is:

That was fun!

Oh, and half the fun was showing it to my cow orkers and having them go "o.O" at it since they didn't recognise what kind of diagram it was. (Upon which I showed it to another cow orker in another office who, I knew, had studied computer science; he recognised it immediately, and I would have been rather disappointed if he hadn't. All my immediate cow orkers had studied other subjects.)

Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 2 comments