From: dale.cts.com!jhb@nosc.mil (John Bollenbacher)
Subject: Re: Suggestion for multivalue boolean case for 9X
Date: 14 Dec 92 21:07:21 GMT [thread overview]
Message-ID: <Bz9pCA.MA6@dale.cts.com> (raw)
Mark Dunbar (dunbar@saifr00.cfsat.honeywell.com) wrote:
: In article <dnsurber.724028252@node_26400> dnsurber@lescsse.jsc.nasa.gov (Dou
glas 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 -
-----------------------------------------------------------------------------
next reply other threads:[~1992-12-14 21:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
1992-12-14 21:07 John Bollenbacher [this message]
-- strict thread matches above, loose matches on Subject: below --
1992-12-13 15:24 Suggestion for multivalue boolean case for 9X agate!spool.mu.edu!yale.edu!jvnc.net!gmd.de!Germany.EU.net!mcsun!sunic!se
1992-12-11 20:08 Alex Blakemore
1992-12-11 19:38 James Crigler
1992-12-11 1:15 Mark Dunbar
1992-12-10 22:57 Douglas N. Surber
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox