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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,bdd718faa7c79f29 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-06-29 11:46:06 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!newshub.sdsu.edu!elnk-pas-nf2!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!stamper.news.atl.earthlink.net!harp.news.atl.earthlink.net!not-for-mail From: Richard Riehle Newsgroups: comp.lang.ada Subject: Re: Overlapping ranges Date: Sun, 29 Jun 2003 11:49:08 -0700 Organization: AdaWorks Software Engineering Message-ID: <3EFF34A4.AF0BB296@adaworks.com> References: <3EFE3491.F968568D@adaworks.com> Reply-To: richard@adaworks.com NNTP-Posting-Host: 3f.bb.80.d5 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Server-Date: 29 Jun 2003 18:46:06 GMT X-Mailer: Mozilla 4.7 [en] (Win98; I) X-Accept-Language: en Xref: archiver1.google.com comp.lang.ada:39899 Date: 2003-06-29T18:46:06+00:00 List-Id: AG wrote: > "Richard Riehle" wrote in message > news:3EFE3491.F968568D@adaworks.com... > > AG wrote: > > > > > Assuming I have a package declaration like this: > > > > > > package range is > > > type x1 is range 0..255; > > > type x2 is range 127..2**15-1; > > > end ranges; > > > > > > Is there a way to declare a function > > > using that package that will accept > > > values of either x1 or x2 (and nothing > > > else) restricted to the range 127..255 ? > > > > Perhaps I don't understand why this is a problem for > > you. Why not something such as, > > Because I don't want to allow an illegal > value to make it inside the function > (not even to raise an exception) > > What I was after was some implementation > that won't need custom exceptions/error > codes or so. This is a good argument for the addition of pre-conditions, post-conditions, and invariants to the language. I like the designations from Eiffel. So the function might look like, function Fudge(A, B : Number'Base) return Number'Base; require A in X2'First..X1'Last; -- pre-condition require B in X2'First..X1'Last; -- pre-condition ensure return in X2'First..X2'Last; -- post-condition The only problem now is what the program does with a pre- or post-condition violation. The answer to this question is not as trivial as it might at first seem. Richard Riehle