From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,35ee5809875c7607,start X-Google-Attributes: gid103376,public From: "W. Wesley Groleau (Wes)" Subject: GoTo in FSM (was Help with Exceptions) Date: 1996/05/15 Message-ID: <9605151336.AA03830@most>#1/1 X-Deja-AN: 154939720 sender: Ada programming language processor" at may 15, 96 12: 01 (midnight) comments: Gated by NETNEWS@AUVM.AMERICAN.EDU mailer: Elm [revision: 70.85] newsgroups: comp.lang.ada Date: 1996-05-15T00:00:00+00:00 List-Id: I keep hearing about the value of GoTo for a finite state machine. Perhaps my understanding of an FSM is incorrect, but every time I've coded what I THOUGHT was a state machine, I used neither GoTo nor recursion and didn't think the code was exceptionally ugly. With Ada 83 the awkward part was defining (and _maintaining_) an enumerated type with one literal for each action (plus error). Another type enumerated the states. A record type contains one of each. If the conditions that trigger the transition/actions are not discrete, another awkward part is mapping each condition to an enumeration. Now you have an array indexed by trigger and current state of those records. Very readable if line length and size of table don't prevent it. (Which they often do--sigh) loop Trigger := Check_Condition_Or_Input; case State_Transition ( Current_State, Trigger ).Action is when {action_name} => Do_{action_name} (...); when ... when Error => Do_Error_Stuff (...); end case; Current_State := State_Transition ( Current_State, Trigger ).Next_State; end loop; Now I wouldn't call that beautiful, but I wouldn't call it ugly either. And now we have access-to-subprogram, so we can eliminate the case statement and the first enumerated type! (But I'm still opposed to making rules a substitute for thinking--even a rule against GoTo.) -- --------------------------------------------------------------------------- W. Wesley Groleau (Wes) Office: 219-429-4923 Magnavox - Mail Stop 10-40 Home: 219-471-7206 Fort Wayne, IN 46808 elm (Unix): wwgrol@pseserv3.fw.hac.com ---------------------------------------------------------------------------