Finite State Machine
Sunday, 29 May 2005 21:04At 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.)
no subject
Date: Tuesday, 31 May 2005 17:31 (UTC)no subject
Date: Tuesday, 31 May 2005 19:59 (UTC)Nope; this was a conscious decision, too. (There was a bit just below, which I cropped since it didn't look so neat, which said something like "This disallows 89. and .7", or something like that.) We considered both forms and felt they weren't necessary -- or, as a stronger statement, that they were undesirable and shouldn't be matched.
No exponentials? :-)
Nope. The routine was intended primarily for monetary values, which aren't usually expressed in scientific notation.