From: Lao Xiao Hai <laoxhai@ix.netcom.com>
Subject: Re: disjoint ranges ?
Date: 2000/10/13
Date: 2000-10-13T19:02:11+00:00 [thread overview]
Message-ID: <39E75AE3.90F858CE@ix.netcom.com> (raw)
In-Reply-To: 39E612C9.9BF98CD3@laas.fr
Philippe Torres wrote:
> A very dumb question but i can't find the right syntax so here i am.
> How can i declare a type or subtype with a disjoint range ?
>
> Example :
>
> If i declare :
> ---
> type Hours is new Integer range 0 .. 23 ;
> --
> i would like a
> ---
> subtype Lunch_Hours is Hours range 7..9 & 12..14 & 19..21 ;
> ---
The problem of disjoint ranges came up for me many years ago on a different
project. I
even suggested this as a capability for Ada 9X, but my suggestion either
fell through the
cracks or I submitted it incorrectly.
My first attempt at a solution was to try to overload the "in" test as a
boolean function. That
turns out to be illegal for a variety of reasons that require careful study
of the language rules
for the "in" test. It turns out that membership tests are not
operations/operators in Ada.
I finally ended up declaring a function that would do this test, but did
not use operator
overloading. It does solve the problem, but requires you call the
function each place
you intend to use a value of the type.
A better approach would probably be to add a capability for assertion
checking.
This simple mechanism could be added at the type level or the subprogram
level
within the package specification. The notion of range checks was a good
one in
the early design of Ada. Perhaps the same thing can be accomplished
through
assertions in some future version.
Richard Riehle
next prev parent reply other threads:[~2000-10-13 0:00 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-10-12 0:00 disjoint ranges ? Philippe Torres
2000-10-12 0:00 ` Pat Rogers
2000-10-12 0:00 ` Ehud Lamm
2000-10-12 0:00 ` Pat Rogers
2000-10-13 0:00 ` Ehud Lamm
2000-10-13 0:34 ` Jeff Carter
2000-10-13 0:00 ` Philippe Torres
2000-10-14 3:12 ` Robert Dewar
2000-10-16 0:00 ` Robert A Duff
2000-10-16 0:00 ` Robert Dewar
2000-10-16 0:00 ` Lao Xiao Hai
2000-10-17 0:00 ` Robert A Duff
2000-10-17 0:00 ` Lao Xiao Hai
2000-10-18 0:00 ` dmitry6243
2000-10-18 0:00 ` Robert Dewar
2000-10-18 0:00 ` Robert A Duff
2000-10-19 3:08 ` Overloading "in" (was: disjoint ranges ?) Jeff Carter
2000-10-19 0:00 ` Ehud Lamm
2000-10-21 0:00 ` Robert Dewar
2000-10-21 0:00 ` Jeff Carter
2000-10-13 0:00 ` disjoint ranges ? Marin David Condic
2000-10-14 3:14 ` Robert Dewar
2000-10-13 0:00 ` Philippe Torres
2000-10-13 0:00 ` wayne lydecker
2000-10-13 0:00 ` Lao Xiao Hai
2000-10-23 0:00 ` Charles Hixson
2000-10-24 0:00 ` dmitry6243
2000-10-13 0:00 ` wayne lydecker
2000-10-13 0:00 ` Lao Xiao Hai [this message]
2000-10-14 3:17 ` Robert Dewar
2000-10-16 0:00 ` Robert A Duff
2000-10-24 0:00 ` Andrew Cooke
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox