comp.lang.ada
 help / color / mirror / Atom feed
From: "John G. Volan" <johnvolan@sprintmail.com>
Subject: Re: GOTO considered necessary (reworked)
Date: 1997/06/23
Date: 1997-06-23T00:00:00+00:00	[thread overview]
Message-ID: <33AE29D6.7258@sprintmail.com> (raw)
In-Reply-To: 33A8DB59.776F@hello.nl

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 4293 bytes --]


> > John Volan said
> >
> > <<If the structure were available in the language, of course there would
> > be no question of using gotos for the same purpose.  Barring that, gotos
> > can be used to _simulate_ this structure, but this will always be a
> > dangerous practice, because the gotos are only at best a simulation of
> > the actual construct the programmer has in mind.  Gotos lack
> > "robustness"; certain important properties of the hypothetical structure
> > (e.g., prevention of "fall-through" between states in an FSA) cannot be
> > guaranteed except by programmer vigilance.
> > >>

> Robert Dewar wrote:
> >
> > First, to me, the mapping of states into sections of code, and the mapping
> > of transitions as gotos, seems pretty direct -- direct enough that I do not
> > think it would make sense to dream up some syntactic gizmo -- although as
> > Robert Eachus points out, a preprocessor can very well provide the equivalent
> > of this syntactic gizmo.

I would not suggest inventing an entirely distinct syntactic gizmo for
Ada (or any similar language), simply because there would not be a
sufficient number of applications to warrant the added complexity in the
language.

Karel Th�nissen wrote:
> 
> A gizmo like this:
> 
> gizmo State : (one, two, three);
>    -- the state variable is private to the gizmo (like loop indices)
>    -- the state variable is read-only, but can change (like loop
> indices)
>    initialStuff;
>    transit one;
> state one;
>    blaBlaTalk;
>    transit ....;
> state two;
>    smallTalk; -- use State as a read-only variable like a loop index
>    transit ....;
> state three;
>    fileBusterTalk;
>    terminate; -- or something of that kind; needs more braincells spent
> end gizmo;

How about this instead:

  type State_Type is (One, Two, Three);
  State : State_Type := State_Type'First;
  ...

  FSA_Name:
  loop
    case State is
    when One =>
      ...
      if ... then
        State := ...
      elsif ... then
        State := ...
      else
        State := ...
      end if;

    when Two =>
      ...

    when Three =>
      ...

    end case;
  end loop FSA_Name;

i.e., exactly the loop+case idea, but with the following addition:

  pragma Finite_State_Automaton (FSA_Name, State);

This pragma would enforce the following criteria: (1) FSA_Name must be
the name of a loop. (2) The loop must contain only a case statement. (3)
The controlling expression of this case statement must be the State
variable given in the pragma. (4) Every when-clause in the case
statement must end with an explicit assignment of the State variable to
some value, or with a named exit from the loop. (4a) If a given
transition is from one state to the same state, this still must be
explicitly expressed with an assignment statement.  (4b) If there is
more than one possible transition from a given state, requiring
conditional code to discriminate the different possibilities, then each
branch of the conditional logic must end with an explicit assignment of
the State variable (or loop exit).

The advantage of using a pragma for this rather than a new syntax is
that it doesn't require any actual change in the language definition.
Instead, it just layers some special-case semantics on the existing
syntax of the language, which seems quite appropriate for this special
case situation.

I suppose a similar sort of pragma might be devised for the code+goto
style, requiring that every conditional branch within a given code-block
end with an explicit goto.

But again, it's hardly worth the effort to design and implement such a
pragma, given the low demand for FSAs in most software. 

------------------------------------------------------------------------
Internet.Usenet.Put_Signature 
  (Name       => "John G. Volan",
   Employer   => "Texas Instruments Advanced C3I Systems, San Jose, CA",
   Work_Email => "jvolan@ti.com",
   Home_Email => "johnvolan@sprintmail.com",
   Slogan     => "Ada95: World's *FIRST* International-Standard OOPL",
   Disclaimer => "My employer never defined these opinions, so using" & 
                 "them would be totally erroneous ... or is that"     &
                 "just nondeterministic behavior now? :-) ");
------------------------------------------------------------------------




  parent reply	other threads:[~1997-06-23  0:00 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-06-11  0:00 GOTO considered necessary (reworked) Samuel Mize
1997-06-11  0:00 ` Bryce Bardin
1997-06-12  0:00 ` Michael F Brenner
1997-06-17  0:00   ` Robert Dewar
1997-06-17  0:00     ` Robert A Duff
1997-06-20  0:00       ` Robert Dewar
1997-06-21  0:00         ` Robert A Duff
1997-06-21  0:00           ` Robert Dewar
1997-06-12  0:00 ` Anonymous
1997-06-12  0:00   ` Robert Dewar
1997-06-12  0:00     ` John G. Volan
1997-06-13  0:00       ` Robert A Duff
1997-06-16  0:00         ` John G. Volan
1997-06-17  0:00           ` Robert Dewar
1997-06-17  0:00             ` Robert A Duff
1997-06-18  0:00               ` Spam Hater
1997-06-20  0:00               ` Robert Dewar
1997-06-20  0:00               ` Robert Dewar
1997-06-21  0:00                 ` Robert A Duff
1997-06-21  0:00                   ` Robert Dewar
1997-06-25  0:00               ` Wolfgang Gellerich
1997-06-25  0:00                 ` Michael F Brenner
1997-06-26  0:00                   ` Wolfgang Gellerich
1997-06-25  0:00                 ` Samuel T. Harris
1997-06-19  0:00             ` Karel Th�nissen
1997-06-19  0:00               ` Karel Th�nissen
1997-06-23  0:00               ` John G. Volan [this message]
1997-06-23  0:00                 ` Robert Dewar
1997-06-24  0:00                   ` Brian Rogoff
1997-06-25  0:00                   ` Featuritis not always bad (was re: GOTO considered necessary) Karel Th�nissen
1997-06-26  0:00                     ` Robert Dewar
1997-06-26  0:00                       ` Karel Th�nissen
1997-06-23  0:00                 ` GOTO considered necessary (reworked) Spam Hater
1997-06-25  0:00                 ` Karel Th�nissen
1997-06-23  0:00             ` John G. Volan
1997-06-17  0:00           ` Robert I. Eachus
1997-06-17  0:00           ` Robert A Duff
1997-06-25  0:00             ` Van Snyder
1997-07-21  0:00           ` Shmuel (Seymour J.) Metz
1997-06-12  0:00   ` John G. Volan
1997-06-16  0:00     ` Anonymous
1997-06-13  0:00 ` Robert A Duff
1997-06-14  0:00   ` Robert Dewar
1997-06-16  0:00     ` Spam Hater
1997-06-17  0:00       ` Robert Dewar
1997-06-17  0:00         ` Spam Hater
1997-06-16  0:00     ` Robert A Duff
1997-06-17  0:00       ` Spam Hater
1997-06-17  0:00         ` Robert A Duff
1997-06-19  0:00           ` Spam Hater
1997-06-17  0:00         ` Robert Dewar
1997-06-17  0:00           ` Spam Hater
1997-06-17  0:00           ` Robert A Duff
1997-06-19  0:00             ` John Herro
1997-06-25  0:00               ` Function result Van Snyder
1997-06-27  0:00                 ` Jon S Anthony
1997-06-27  0:00                 ` Robert Dewar
1997-06-20  0:00             ` GOTO considered necessary (reworked) Robert Dewar
1997-06-14  0:00   ` Samuel Mize
1997-06-14  0:00     ` Matthew Heaney
1997-06-14  0:00   ` Samuel Mize
1997-06-16  0:00 ` Anonymous
1997-06-16  0:00   ` Robert Dewar
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox