comp.lang.ada
 help / color / mirror / Atom feed
From: darwin.sura.net!spool.mu.edu!umn.edu!The-Star.honeywell.com!saifr00.cfsat .honeywell.com!dunbar@gatech.edu  (Mark Dunbar)
Subject: Re: Suggestion for multivalue boolean case for 9X
Date: 11 Dec 92 01:15:15 GMT	[thread overview]
Message-ID: <1992Dec11.011515.2859@saifr00.cfsat.honeywell.com> (raw)

In article <dnsurber.724028252@node_26400> dnsurber@lescsse.jsc.nasa.gov (Dougl
as 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.

             reply	other threads:[~1992-12-11  1:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1992-12-11  1:15 Mark Dunbar [this message]
  -- strict thread matches above, loose matches on Subject: below --
1992-12-14 21:07 Suggestion for multivalue boolean case for 9X John Bollenbacher
1992-12-13 15:24 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-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