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=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3c55100a141db64d X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1993-03-22 18:44:42 PST Newsgroups: comp.lang.ada Path: sparky!uunet!math.fu-berlin.de!dww From: dww@math.fu-berlin.de (Debora Weber-Wulff) Subject: Re: Membership in "set" of characters Message-ID: Sender: news@math.fu-berlin.de (Math Department) Organization: Free University of Berlin, Germany References: <1993Mar19.195712.9187@wdl.loral.com> <1ok4ts$3cv@huon.itd.adelaide.edu.au> Date: Mon, 22 Mar 1993 12:22:49 GMT Date: 1993-03-22T12:22:49+00:00 List-Id: Thanks to all who wrote with information about my problems with membership and FIXED/FLOAT. Here's a short summary of the other answers I received: FIXED/FLOAT Just using type DM is delta 0.01 range 0.0 .. 1000.0; gets me in trouble because the delta is a positive fraction that causes rounding errors. I need for DM'small use 0.01; to make it work as I expect, but I've been advised to leave FIXED alone until I understand more about Ada :-) I've included a complete letter with some great advice at the end of this summary. There's an article in Ada Europe'92 proceedings [is that published in LNCS? I've not heard of it before, but they seem to be in their 13th year! Is there a FAQ for this group??? ] by Ben Brosgol, Robert Eachus and Dave Emery about Ada Decimal Arithmetic. ajpo.sei.cmu.edu (128.237.2.253) has a library of representations for decimal arithmetic at ADAR-1.0.tar.Y and a book called "Ada Quality and Style" Membership Problem Lots of suggestions! * Use subtypes! * use a case statement! * make a function is_in (c:character; s:string) return Boolean is ... * use okay := affirmatives'VALUE (CHARACTER'IMAGE(ch)) IN affirmatives; * roll my own set as described below - that sounds like the way I want to go. It reads a tad easier than the previous suggestion :-) ----- included file ----- In article you write: > This is another one of those "why won't this work?" for the experts. > I'm stumped. As far as I can decode the LRM and > see from 2 textbooks I consulted, this ought to work. nope > -- Why won't membership work here? here's the short answer: for the type of thing you are doing, you can create a set ADT. a simple way to do that in Ada for a relatively small discrete universe like character is to use a boolean array. you can pack it to make it smaller, which effectively creates a bitmap. this is what Pascal sets basically are - and this way Ada doesnt have to explicitly support sets in the language. its just one kind of data type that you can build. type char_predicates is array (character) of boolean; pragma pack (char_predicates); affirmative : constant char_predicates := char_predicates'('y'|'Y'|'j'|'J'|'o'|'O' => true, others => false); ... okay := affirmative(ch); you could also make affirmative a function instead of a constant array to save space. you could do this later if necessary without changing the clients because the syntax for a function call is identical to that of an array reference. its a little more typing than Pascal in this case, but its much easier to tell whats going on. > I'm currently quite frustrated with the type system after writing a little program > to calculate the return on investment. > Is it me? Is it Meridian? Or is this the agony of using Ada? It takes a while to get used to Ada's strong typing. It seems overly strict at first, but once you understand the rules well, they dont get in the way very much at all. in fact, they often help prevent errors. still that initial period can be rough, since its easy to make things much stricter than you need without realizing it. and then blame the language when it is enforcing exactly the rules that you asked for. derived types are a frequent culprit. they can be very helpful when you need them, but can easily make it difficult to write any expression if over-used. you can get very similar behavior to other languages like Pascal with respect to numeric types if you wish. 1. avoid derived types until you have learned the rest of Ada well. then use them judiciously and carefully. (derived types have the form "type xxx is new yyy") (also avoid the form "type xxx is range a .. b" at first) 2. use subtypes instead, "subtype xxx is yyy range a .. b" 3. avoid fixed point, use float instead. 4. if you frequently use a mixed mode operation (i.e. multiply integers and floats to get floats) then define a function so that you dont have to keep performing conversions. function "*" (left : integer; right : float) return float is ... 5. when you feel comfortable with Ada, get a few books and try out derived types and floats. they do have good uses. the book Ada Quality and Style available on ajpo.sei.cmu.edu has a section on derived types and subtypes that might help (disclaimer: I helped write that part) the FAQ on the same machine describes several good books as well (thanks to Mike Feldman). good luck. P.S. Meridian is a pretty good compiler, but if you get the chance or have something really serious, use DECs. -- --------------------------------------------------- Alex Blakemore alex@cs.umd.edu NeXT mail accepted ----- end included file ----- -- Debora Weber-Wulff, Professorin fuer Softwaretechnik snail: Technische Fachhochschule, FB Informatik, Luxemburgerstr. 10, 1000 Berlin 65 email: dww@informatik.tfh-berlin.dbp.de