comp.lang.ada
 help / color / mirror / Atom feed
* Re: null range from 1 element discrete type
  1999-11-19  0:00 null range from 1 element discrete type Duncan Sands
  1999-11-19  0:00 ` Robert I. Eachus
@ 1999-11-19  0:00 ` Matthew Heaney
  1999-11-19  0:00   ` Robert Dewar
  1 sibling, 1 reply; 8+ messages in thread
From: Matthew Heaney @ 1999-11-19  0:00 UTC (permalink / raw)


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>




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: null range from 1 element discrete type
  1999-11-19  0:00 ` Matthew Heaney
@ 1999-11-19  0:00   ` Robert Dewar
  0 siblings, 0 replies; 8+ messages in thread
From: Robert Dewar @ 1999-11-19  0:00 UTC (permalink / raw)


In article <3835671c_2@news1.prserv.net>,
  "Matthew Heaney" <matthew_heaney@acm.org> wrote:

> You could try this:
>
>   type ET is (A);
>
>   subtype Null_ET is ET range A .. ET'Pred (A);

don't bother to try this

>
> but I don't think this will work

it won't!



Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* null range from 1 element discrete type
@ 1999-11-19  0:00 Duncan Sands
  1999-11-19  0:00 ` Robert I. Eachus
  1999-11-19  0:00 ` Matthew Heaney
  0 siblings, 2 replies; 8+ messages in thread
From: Duncan Sands @ 1999-11-19  0:00 UTC (permalink / raw)
  To: comp.lang.ada

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?

As you may guess, I have a generic package that takes a discrete
type parameter T, and I want it to work correctly in this degenerate
case.  At some point the package declares an array type, eg
type A is array (T range <>) of Float;
and I want to declare a null slice of type A.  At this point
I run into the above problem...

Thanks for any help,

Duncan.

 ----
 Laboratoire de Topologie et Dynamique, Batiment 425,
 Universite de Paris-Sud, 91405 Orsay, France
 sands@topo.math.u-psud.fr
----









^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: null range from 1 element discrete type
  1999-11-19  0:00 null range from 1 element discrete type Duncan Sands
@ 1999-11-19  0:00 ` Robert I. Eachus
  1999-11-22  0:00   ` Robert A Duff
                     ` (2 more replies)
  1999-11-19  0:00 ` Matthew Heaney
  1 sibling, 3 replies; 8+ messages in thread
From: Robert I. Eachus @ 1999-11-19  0:00 UTC (permalink / raw)


Duncan Sands 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?
> 
> As you may guess, I have a generic package that takes a discrete
> type parameter T, and I want it to work correctly in this degenerate
> case.  At some point the package declares an array type, eg
> type A is array (T range <>) of Float;
> and I want to declare a null slice of type A.  At this point
> I run into the above problem...

    Technically there is no "perfect" solution, as the compiler is
allowed to choose a size of zero bits for such a type.  But if the
(sub)type is a generic formal type, you shouldn't have to worry about
this possibility.

    Since you always want a null range try:  T'Val(1) .. T'Val(0)  Since
'Val returns the base type of T, as long as the base type of T contains
at least one bit you are safe.

-- 

                                        Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: null range from 1 element discrete type
  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
  2 siblings, 1 reply; 8+ messages in thread
From: Robert Dewar @ 1999-11-22  0:00 UTC (permalink / raw)


In article <3835D5A0.F906D31D@mitre.org>,
  "Robert I. Eachus" <eachus@mitre.org> wrote:
> Since you always want a null range try:  T'Val(1) ..
> T'Val(0)  Since
> 'Val returns the base type of T, as long as the base type of T
> contains at least one bit you are safe.
>
> --
>
>                                         Robert I. Eachus


How an this possibly be any better than T'Last .. T'First, which
also doesn't work, as the original question notes!

Robert, the whole POINT of this question is how to get something
that works when T only has one element. Your suggestion will
of course raise CE in this case.

There is no solution that works generally.


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: null range from 1 element discrete type
  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
  2 siblings, 0 replies; 8+ messages in thread
From: Robert Dewar @ 1999-11-22  0:00 UTC (permalink / raw)


In article <3835D5A0.F906D31D@mitre.org>,
  "Robert I. Eachus" <eachus@mitre.org> wrote:
>     Technically there is no "perfect" solution, as the
compiler is
> allowed to choose a size of zero bits for such a type.  But if
the
> (sub)type is a generic formal type, you shouldn't have to
worry about
> this possibility.


By the way, the above is a complete red herring, this has
nothing to do with the number of bits used to represent the
type, it is a question purely at the semantic level.


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: null range from 1 element discrete type
  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
  2 siblings, 0 replies; 8+ messages in thread
From: Robert A Duff @ 1999-11-22  0:00 UTC (permalink / raw)


"Robert I. Eachus" <eachus@mitre.org> writes:

>     Technically there is no "perfect" solution, as the compiler is
> allowed to choose a size of zero bits for such a type.  

The compiler is *required* to choose 'Size = 0, and of course that's the
natural thing for the compiler to do -- anything else would require a
special case in the compiler.

But I don't see what 'Size has to do with the issue.

>...But if the
> (sub)type is a generic formal type, you shouldn't have to worry about
> this possibility.
> 
>     Since you always want a null range try:  T'Val(1) .. T'Val(0)  Since
> 'Val returns the base type of T, as long as the base type of T contains
> at least one bit you are safe.

T'Val(1) will raise Constraint_Error if T is an enum type with only one
value.  The number of bits allocated for objects of type T has nothing
to do with this.

- Bob




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: null range from 1 element discrete type
  1999-11-22  0:00   ` Robert Dewar
@ 1999-11-25  0:00     ` Niklas Holsti
  0 siblings, 0 replies; 8+ messages in thread
From: Niklas Holsti @ 1999-11-25  0:00 UTC (permalink / raw)


Robert Dewar wrote:
> 
> There is no solution that works generally.

Perhaps we need a new attribute, Some_Type'Null_Range, to represent
a null range of Some_Type values.




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~1999-11-25  0:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-11-19  0:00 null range from 1 element discrete type Duncan Sands
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
1999-11-19  0:00 ` Matthew Heaney
1999-11-19  0:00   ` Robert Dewar

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