From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,4b06f8f15f01a568 X-Google-Attributes: gid103376,public From: stt@houdini.camb.inmet.com (Tucker Taft) Subject: Re: Expressive Case Statements (was: Software landmines) Date: 1998/09/01 Message-ID: #1/1 X-Deja-AN: 386927973 Sender: news@inmet.camb.inmet.com (USENET news) X-Nntp-Posting-Host: houdini.camb.inmet.com References: <6shit4$eaj@dfw-ixnews5.ix.netcom.com> Organization: Intermetrics, Inc. Newsgroups: comp.lang.ada Date: 1998-09-01T00:00:00+00:00 List-Id: Richard D Riehle (laoXhai@ix.netcom.com) wrote: : ... : EVALUATE condition-1 ALSO condition-2 ALSO condition-3 : : WHEN TRUE ALSO TRUE ALSO FALSE : PERFORM : some action-stub statements : END-PERFORM : WHEN TRUE ALSO FALSE ALSO FALSE : PERFORM : some action-stub statements : END-PERFORM : WHEN FALSE ALSO FALSE ALSO TRUE : PERFORM : some action-stub statements : END-PERFORM : END-EVALUATE : ... : It is certainly easy to represent any set of conditions with a sequence : of if ... elsif statements but I am seeking something else. What I have : been trying to accomplish is some generalized algorithm in Ada that : allows me to design a package that approximates the power of the EVALUATE : statement in COBOL. What about: type Cond_Array is array(Positive range <>) of Boolean; ... declare Conds : constant Cond_Array := (condition-1, condition-2, condition-3); begin if Conds = (true, true, false) then ... elsif Conds = (true, false, false) then ... elsif Conds = (false, false, true) then ... end if; end; This certainly seems close enough, and captures the decision table nature of the solution. This doesn't use any "fancy" Ada 95 features. In fact, it doesn't use any Ada 95 features at all! If you require a case-statement solution, the following general pattern would work: type Cond3 is (FFF, FFT, FTF, FTT, TFF, TFT, TTF, TTT); Cond3_Map : array(Boolean, Boolean, Boolean) of Cond3 is (((FFF, FFT), (FTF, FTT)), ((TFF, TFT), (TTF, TTT))); ... case Cond3_Map(condition-1, condition-2, condition-3) is when TTF => ... when TFF => ... when FFT => ... when others => null; end case; : ... : Richard Riehle : richard@adaworks.com : http://www.adaworks.com -- -Tucker Taft stt@inmet.com http://www.inmet.com/~stt/ Intermetrics, Inc. Burlington, MA USA