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-23 03:44:25 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!newshub.sdsu.edu!elnk-pas-nf2!elnk-pas-nf1!newsfeed.earthlink.net!newsfeed2.easynews.com!newsfeed1.easynews.com!easynews.com!easynews!c03.atl99!news.webusenet.com!pc01.webusenet.com!fe02.atl2.webusenet.com.POSTED!not-for-mail From: "David C. Hoos" Newsgroups: comp.lang.ada References: <3EF5EDA1.1010702@attbi.com> Subject: Re: Overlapping ranges MIME-Version: 1.0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 7bit X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Message-ID: X-Complaints-To: abuse@usenetserver.com X-Abuse-Info: Please be sure to forward a copy of ALL headers X-Abuse-Info: Otherwise we will be unable to process your complaint properly. NNTP-Posting-Date: Mon, 23 Jun 2003 06:32:15 EDT Date: Mon, 23 Jun 2003 05:46:19 -0500 Xref: archiver1.google.com comp.lang.ada:39589 Date: 2003-06-23T05:46:19-05:00 List-Id: Neither example will compile because the declaration subtype x1_and_x2_range is range x1(x2'first)..x1'last; is illegal; Example 2 will not compile because the declaration function f(x1_an_x2_range) return boolean; is illegal. Did you mean this? function f(x : x1_and_x2_range) return boolean; Both examples would give constraint error at runtime because abc = f (0); has an argument outside the range of x1_and_x1_range. "AG" wrote in message news:kszJa.45970$JA5.800915@news.xtra.co.nz... > "Robert I. Eachus" wrote in message > news:3EF5EDA1.1010702@attbi.com... > > > Now let's see which problem requirements seem silly: > > > > Why are X1 and X2 different types rather than subtypes? > > Because I'd rather keep them separate except in the case > of that one specialised function which knows enough about > them to handle either. Declaring them as subtypes makes > all sorts of other things available too. > > > Why is X1 not a modular type? > > I'm afraid I didn't follow you there: I'm not interested > in modular or wrap-around semantics, so why should it be? > > > > > Why do you need the Constraint_Error to be raised outside the function > > call? Wouldn't raising it inside OR outside work just fine? > > No. Because it results in an externally visible different behaviour. > Let's see an example (a bit silly as all examples are but an example > nevertheless): > > package overlap is > type x1 is range 0..255; > type x2 is range 127..2**15-1; > subtype x1_and_x2_range is range x1(x2'first)..x1'last; > -- function f(x1_an_x2_range) return boolean; -- *1* > -- function f(x: x1) return boolean; -- *2* > end; > > with ada.text_io; use ada.text_io; > package body overlap is > -- *1* > function f(x1_and_x2_range) return boolean is > a: x1_and_x2_range; > begin > put_line("Here"); > a := x; > return false; > end; > > -- *2* > function f(x: x1) return boolean is > -- same code as above; > end; > > Finally, the use: abc := f(0); > > The result (running it under GNAT): > > Uncommenting version *2* compiles fine > and generates constraint error when run. > > Uncommenting version *1* generates > exactly the same error when run but also > provides two compile-time warnings. > Seems to be a valuable addition, doesn't it? > > > Why do you want one function which accepts parameters of two different > > types? My solution has the call to one calling the other, but still... > > Someone else has already suggested the overloading solution. > Thanks, that seems like a good idea > . > > > _______________________________________________ > comp.lang.ada mailing list > comp.lang.ada@ada.eu.org > http://ada.eu.org/mailman/listinfo/comp.lang.ada > >