home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.ada
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!agate!dog.ee.lbl.gov!news!nosc!dale.cts.com!jhb
- From: jhb@dale.cts.com (John Bollenbacher)
- Subject: Re: Suggestion for multivalue boolean case for 9X
- Message-ID: <Bz9pCA.MA6@dale.cts.com>
- Sender: news@dale.cts.com (USENET News Account)
- Organization: Titan Linkabit Corporation
- X-Newsreader: Tin 1.1 PL5
- References: <1992Dec11.011515.2859@saifr00.cfsat.honeywell.com>
- Date: Mon, 14 Dec 1992 21:07:21 GMT
- Lines: 80
-
- Mark Dunbar (dunbar@saifr00.cfsat.honeywell.com) wrote:
- : 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
- : > s_t_t_t;
- : > else
- : > s_t_t_f;
- : > end if;
- : > else
- : > if cond_3 then
- : > s_t_f_t;
- : > else
- : > s_t_f_f;
- : > end if;
- : > end if;
- :
- : [etc]...
- :
- : >I find this hard to read and even harder to maintain. Cond_3 appears
- : >four times. That's a maintenance nightmare. A case statement that
- : >worked on arrays of booleans would be a big improvement. Something like
- : >the following:
- : >
- : > case (cond_1, cond_2, cond_3) is
- : > when (true, true, true ) =>
- : > s_t_t_t;
- : > when (true, true, false) =>
- : > s_t_t_f;
- : > when (true, false, true ) =>
- : > s_t_f_t;
- : > when (true, false, false) =>
- : > s_t_f_f;
- :
- : [etc]...
- : >
- : >Douglas Surber
- : >Lockheed
- : >Houston, TX
- : >
- : 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
- : ...
- : elsif ( not Cond_1 ) and ( Cond_2 ) and ( not Cond_3 ) then
- : ...
- : elsif ( not Cond_1 ) and ( Cond_2 ) and ( Cond_3 ) then
- : ...
- : elsif ( Cond_1 ) and ( not Cond_2 ) and ( not Cond_3 ) then
- : ...
- :
- : etc.
- :
- : Although I do agree the case statement would be more elegant (sp?) and
- : potentially faster if there were enough branches to cancel out the
- : overhead of a case.
-
- Though I also agree that the original posting has merit, another possibility
- that I have used is something like:
-
- declare
- type BOOLS is array (1..3) of BOOLEAN;
- VAL : constant BOOLS := (COND_1, COND_2, COND_3);
- begin
- if VAL = (TRUE, TRUE, TRUE) then
- ...
- elsif VAL = (TRUE, TRUE, FALSE) then
- ...
- etc.
- --
- -----------------------------------------------------------------------------
- - John Bollenbacher jhb@dale.cts.com -
- - Titan Linkabit Corp. (619) 552-9963 -
- - 3033 Science Park Rd. -
- - San Diego, Ca. 92121 -
- -----------------------------------------------------------------------------
-