comp.lang.ada
 help / color / mirror / Atom feed
From: "AG" <ang@xtra.co.nz>
Subject: Re: Overlapping ranges
Date: Sun, 22 Jun 2003 14:58:05 +1200
Date: 2003-06-22T14:58:05+12:00	[thread overview]
Message-ID: <5W8Ja.43776$JA5.768297@news.xtra.co.nz> (raw)
In-Reply-To: My7Ja.54206$hz1.129990@sccrnsc01


"Mark A. Biggar" <mark@biggar.org> wrote in message
news:My7Ja.54206$hz1.129990@sccrnsc01...
> 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.

It's not a bug it's a feature  -)

>  x1 and x2 are different
> types and there is no way to declare a parameter with more then one
> type.

Exactly. And that's the problem - I'm looking for a way
to declare a function [and/or whatever] that could handle
values of either of the two [test-bed of course] types and,
on top of that, impose range restrictions on the values passed in.

> 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;

Sorry, won't work. V1, V2 and V1x2 of the subtypes
are all mutually assignment-compatible. How would
the function know what you passed in?

> 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;

That's a little bit better but: you've declared
the intersect [sub]type as coming from the type
xBase. What exactly does it have to do with
derived types x1 & x2?

> Another option is to use a discriminated record:

No, sorry, let's not go there. I know it's possible
but it's not exactly what I'm after ...





  reply	other threads:[~2003-06-22  2:58 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 [this message]
2003-06-22  3:17     ` tmoran
2003-06-22 17:55   ` Robert I. Eachus
2003-06-23  9:05     ` AG
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