comp.lang.ada
 help / color / mirror / Atom feed
From: "Matthew Heaney" <matthew_heaney@acm.org>
Subject: Re: null range from 1 element discrete type
Date: 1999/11/19
Date: 1999-11-19T00:00:00+00:00	[thread overview]
Message-ID: <3835671c_2@news1.prserv.net> (raw)
In-Reply-To: v03020900b45ad0cb9379F@[192.54.146.15]

In article <v03020900b45ad0cb9379F@[192.54.146.15]> , Duncan Sands 
<sands@topo.math.u-psud.fr>  wrote:

> Suppose I have a discrete type (eg an enumeration type) T
> containing just one element.  I would like to define a subtype
> with a null range.  If T had more than one element, I could use
> T'Last .. T'First, but this won't work here.  How to get a null
> range in this case?

You're allowed to violate the range of the subtype, e.g.

  S : String (1 .. 0);

is perfectly OK, even though 0 is outside the range of the index subtype
Positive, because it is still in the range of Integer'Base.

The problem is that an enumeration type is its own "base type."  You
could try this:

  type ET is (A);

  subtype Null_ET is ET range A .. ET'Pred (A);

but I don't think this will work, because there is no predecessor of A.
The base type of ET, ET'Base, only includes the values A .. A.

A solution is to declare a base type with extra values, and declare ET
as a subtype, like this:

  type ET_Base is (ET_Base_First, A, ET_Base_Last);

  subtype ET is ET_Base range A .. A;

Now you're free to declare another subtype, of ET, with a null range:

  subtype Null_ET is range A .. ET'Pred (A);

which should work fine.


--
"It is indeed remarkable that this theory [of evolution] has
progressively taken root in the minds of researchers following a series
of discoveries made in different spheres of knowledge," the Pope said.

"The convergence, neither sought nor provoked, of results of studies
undertaken independently from each other constitutes in itself a
significant argument in favour of this theory."

Pope John Paul, 24 Oct 96

<http://christusrex.org/www1/news/10-96/es10-24-96.html>




  reply	other threads:[~1999-11-19  0:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-11-19  0:00 null range from 1 element discrete type Duncan Sands
1999-11-19  0:00 ` Matthew Heaney [this message]
1999-11-19  0:00   ` Robert Dewar
1999-11-19  0:00 ` Robert I. Eachus
1999-11-22  0:00   ` Robert A Duff
1999-11-22  0:00   ` Robert Dewar
1999-11-22  0:00   ` Robert Dewar
1999-11-25  0:00     ` Niklas Holsti
replies disabled

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