home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!news.gtech.com!noc.near.net!hri.com!spool.mu.edu!darwin.sura.net!cs.ucf.edu!crigler
- From: crigler@cs.ucf.edu (James Crigler)
- Newsgroups: comp.lang.ada
- Subject: Re: Suggestion for multivalue boolean case for 9X
- Message-ID: <crigler.724102689@eola.cs.ucf.edu>
- Date: 11 Dec 92 19:38:09 GMT
- References: <dnsurber.724028252@node_26400> <1992Dec11.011515.2859@saifr00.cfsat.honeywell.com>
- Sender: news@cs.ucf.edu (News system)
- Organization: University of Central Florida
- Lines: 43
-
- dunbar@saifr00.cfsat.honeywell.com (Mark Dunbar) writes:
-
- >In article <dnsurber.724028252@node_26400> dnsurber@lescsse.jsc.nasa.gov (Douglas N. Surber) writes:
- >>How many times have you seen code like the following:
- >>
- >> if cond_1 then
- >> if cond_2
- >> if cond_3 then
- >>[...]
- >Using Ada83, instead of the nested if statement, one could do the following:
-
- > if ( not Cond_1 ) and ( not Cond_2 ) and ( not Cond_3 ) then
- > ...
- > elsif ( not Cond_1 ) and ( not Cond_2 ) and ( Cond_3 ) then
- > ...
- > etc.
-
- Having done this enough times to try to find a solution, I use
- this: Write a function that takes the conditions shown above as
- inputs and returns a value of an enumerated type, then case on the
- function return value like this:
-
- type SELECTIONS is (E1, E2, E3);
-
- function SELECTION (C1, C2, C3 : in BOOLEAN) is
- begin
- ...
- end SELECTION;
-
- case SELECTION(COND_1, COND_2, COND_3) is
- when E1 =>
- STMT1;
- when E2 =>
- STMT2;
-
- etc.
-
- This allows the condition set to be arbitrarily complex over an
- arbitrary value set in execution while retaining elegance in form.
- You can apply pragma INLINE to the selection function to obtain
- marginally better exection time (over the non-INLINE'd version.
-
- Jim Crigler
-