comp.lang.ada
 help / color / mirror / Atom feed
From: "AG" <ang@xtra.co.nz>
Subject: Re: Overlapping ranges
Date: Mon, 23 Jun 2003 21:05:09 +1200
Date: 2003-06-23T21:05:09+12:00	[thread overview]
Message-ID: <kszJa.45970$JA5.800915@news.xtra.co.nz> (raw)
In-Reply-To: 3EF5EDA1.1010702@attbi.com

"Robert I. Eachus" <rieachus@attbi.com> 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
.





  reply	other threads:[~2003-06-23  9:05 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-22  0:40 Overlapping ranges AG
2003-06-22  1:23 ` Mark A. Biggar
2003-06-22  2:58   ` AG
2003-06-22  3:17     ` tmoran
2003-06-22 17:55   ` Robert I. Eachus
2003-06-23  9:05     ` AG [this message]
2003-06-23 10:46       ` David C. Hoos
2003-06-24  8:09         ` AG
2003-06-29  0:36 ` Richard Riehle
2003-06-29  6:24   ` AG
2003-06-29  6:42     ` AG
2003-06-29 18:40       ` Richard Riehle
2003-06-29 18:49     ` Richard Riehle
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox