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: Brian Rogoff Subject: Re: Expressive Case Statements (was: Software landmines) Date: 1998/09/01 Message-ID: #1/1 X-Deja-AN: 386957990 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Trace: 904694839 4459 bpr 206.184.139.132 Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1998-09-01T00:00:00+00:00 List-Id: On Tue, 1 Sep 1998, Richard D Riehle wrote: > I realize this was supposed to be about optimizations. But this is the > year of changing the subject what with tails wagging dogs, etc. Ted's > mention of "case statements" reminds me of a problem with which I have > been struggling for quite a while; one for which I finally cry, "Help!" > > There is a language called COBOL in which the ANSI 1995 standard > introduced a fascinating construct called the EVALUATE statement. It > is the most powerful form of a case statement I have seen in any > programming language. More powerful than Ada. More powerful than Eiffel. > More powerful than C++ or Java. Unfortunately, I don't COBOL, but I think I can read your case statement below, and I wonder if the following, in Objective Caml, does the trick: > > One of the forms the EVALUATE statement (there are several options), > allows the programmer to directly represent a decision-table for a > set of conditions with syntax such as, > > 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 let get_val b1 b2 b3 = match (b1, b2, b3) with | (true, true, false) -> perform1 | (true, false, false) -> perform2 | (false, false, true) -> perform3 | (_,_,_) -> perform_default;; I think ML style pattern matching is pretty powerful compared to Ada's, and Prolog's even more so. > In business data process software, such as banking and insurance, the > decision table is useful for representing complex sets of conditions > and their corresponding actions. In military command and control > systems we also see these kinds of complex condition sets. > > 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. Some of the new features of Ada 95 such as generic > formal package parameters, access to subprogram, etc. have helped a > little, but ... As I'm sure you know, you need to create mapping functions to an enumerated type or something similar in order to use Ada's case statement. I don't think there is a general solution, you can't even use tags in case statements. Yeah, I prefer ML for its more powerful pattern matching, but Ada has her charms too. I guess we Ada fans will have to do this by hand; we also have to do it by hand if we want to translate our close cousin language VHDL's case statement to Ada. -- Brian