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: 11 Dec 92 19:38:09 GMT From: agate!spool.mu.edu!darwin.sura.net!cs.ucf.edu!crigler@ucbvax.Berkeley.EDU (James Crigler) Subject: Re: Suggestion for multivalue boolean case for 9X Message-ID: List-Id: dunbar@saifr00.cfsat.honeywell.com (Mark Dunbar) writes: >In article dnsurber@lescsse.jsc.nasa.gov (Doug las 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