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.9 required=5.0 tests=BAYES_00 autolearn=ham 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-21 18:23:57 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!arclight.uoregon.edu!wn13feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi_feed4!attbi.com!sccrnsc01.POSTED!not-for-mail From: "Mark A. Biggar" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.3.1) Gecko/20030425 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Overlapping ranges References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 12.235.88.213 X-Complaints-To: abuse@attbi.com X-Trace: sccrnsc01 1056245036 12.235.88.213 (Sun, 22 Jun 2003 01:23:56 GMT) NNTP-Posting-Date: Sun, 22 Jun 2003 01:23:56 GMT Organization: AT&T Broadband Date: Sun, 22 Jun 2003 01:23:56 GMT Xref: archiver1.google.com comp.lang.ada:39547 Date: 2003-06-22T01:23:56+00:00 List-Id: 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 ? You have a bug in your design abstraction. x1 and x2 are different types and there is no way to declare a parameter with more then one type. This is like the doctor joke: "patient: Doc it hurts when I do this. Doctor: So don't do that!" But if that's really what you want to do this, there are several way to do it. First option fix the abstraction: package range is type xBase is range 0..2**15-1; subtype x1 is xBase range 0..255; subtype x2 is xBase range 127..2**15-1; subtype x1x2Intersect is xbase range 127..255; function foo(p: x1x2Intersect) return ...; end ranges; If you really need two separate types: package range is type xBase is range 0...2**15-1; subtype x1x2Intersect is xBase range 127..255; type x1 is new xBase range xBase'First..255; type x2 is new xBase range 127..xBase'Last; function foo(p: x1x2intersect) return ...; end ranges; But now you must call foo with a view conversion to xBase: a := foo(xBase(200)); Another option is to use a discriminated record: package range is type x1 is range 0..255; type x2 is range 127..2**15-1; type x1x2intersect(b: boolean) is record case b is when false => x1val: x1 range 127..255; when true => x2val: x2 range 127..255; end case; end record; function foo(p: x1x2intersect) return ...; end ranges; But now you need to call foo like: a := foo((false, x1'(200))); or a := foo((true, x2'(200))); Personally, I'd try to get the design fixed :-) -- mark@biggar.org mark.a.biggar@attbi.com