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,8276b2994037cd71 X-Google-Attributes: gid103376,public From: Lao Xiao Hai Subject: Re: disjoint ranges ? Date: 2000/10/13 Message-ID: <39E75AE3.90F858CE@ix.netcom.com>#1/1 X-Deja-AN: 681107938 Content-Transfer-Encoding: 7bit References: <39E612C9.9BF98CD3@laas.fr> X-Accept-Language: en X-Server-Date: 13 Oct 2000 19:02:11 GMT Content-Type: text/plain; charset=us-ascii Organization: MindSpring Enterprises Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 2000-10-13T19:02:11+00:00 List-Id: Philippe Torres wrote: > A very dumb question but i can't find the right syntax so here i am. > How can i declare a type or subtype with a disjoint range ? > > Example : > > If i declare : > --- > type Hours is new Integer range 0 .. 23 ; > -- > i would like a > --- > subtype Lunch_Hours is Hours range 7..9 & 12..14 & 19..21 ; > --- The problem of disjoint ranges came up for me many years ago on a different project. I even suggested this as a capability for Ada 9X, but my suggestion either fell through the cracks or I submitted it incorrectly. My first attempt at a solution was to try to overload the "in" test as a boolean function. That turns out to be illegal for a variety of reasons that require careful study of the language rules for the "in" test. It turns out that membership tests are not operations/operators in Ada. I finally ended up declaring a function that would do this test, but did not use operator overloading. It does solve the problem, but requires you call the function each place you intend to use a value of the type. A better approach would probably be to add a capability for assertion checking. This simple mechanism could be added at the type level or the subprogram level within the package specification. The notion of range checks was a good one in the early design of Ada. Perhaps the same thing can be accomplished through assertions in some future version. Richard Riehle