From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 14 Dec 92 21:07:21 GMT From: dale.cts.com!jhb@nosc.mil (John Bollenbacher) Subject: Re: Suggestion for multivalue boolean case for 9X Message-ID: List-Id: Mark Dunbar (dunbar@saifr00.cfsat.honeywell.com) wrote: : In article 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 - -----------------------------------------------------------------------------