comp.lang.ada
 help / color / mirror / Atom feed
From: johnherro@aol.com (John Herro)
Subject: Re: Ada 83 Style Query
Date: 1996/05/06
Date: 1996-05-06T00:00:00+00:00	[thread overview]
Message-ID: <4mlrsm$2m6@newsbf02.news.aol.com> (raw)
In-Reply-To: 9605061517.AA05599@most


"W. Wesley Groleau (Wes)" <wwgrol@PSESERV3.FW.HAC.COM> writes:
> I'm working on some old code that has a
> long string of elsif checking strings that
> come in from outside against known
> commands.  Seeking opinions on the
> desirability of using an enumerated type
> with 'VAL and a case statement.
     One thing to consider is that none of the commands can match Ada
reserved words, such as BEGIN, REVERSE, ACCEPT, RECORD, END, USE, etc.  If
you write the program with an enumeration type, and later someone wants to
add an END command, you'll have to redesign the program!  However, if none
of the commands match reserved words and you're sure you won't later be
adding such commands, then using an enumeration type is certainly a viable
way of doing it.

> The sore spot is the need for an exception handler ...
     If you do choose to use an enumeration type, adding an exception
handler for the case of an incorrect incoming string should be simple.  I
suggest localizing the scope of the exception handler as much as possible
with a block, like this:
type Command_Type is (Go, Stop, ..., Unrecognized);
Command   : Command_Type;
Input     : String(1 .. 80);
Input_Len : Integer;
...
Get_Line(Input, Input_Len);
begin
   Command := Command_Type'Value(Input(1 .. Input_Len));
exception
   when Constraint_Error => Command := Unrecognized;
end;
case Command is ...

- John Herro
Software Innovations Technology
http://members.aol.com/AdaTutor
ftp://members.aol.com/AdaTutor





  reply	other threads:[~1996-05-06  0:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-05-06  0:00 Ada 83 Style Query W. Wesley Groleau (Wes)
1996-05-06  0:00 ` John Herro [this message]
1996-05-06  0:00 ` Theodore E. Dennison
1996-05-07  0:00 ` Laurent Guerby
replies disabled

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