comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@ni.net (Matthew Heaney)
Subject: Re: Question about base types
Date: 1997/01/30
Date: 1997-01-30T00:00:00+00:00	[thread overview]
Message-ID: <mheaney-ya023280003001970845170001@news.ni.net> (raw)
In-Reply-To: dewar.854626377@merv


In article <dewar.854626377@merv>, dewar@merv.cs.nyu.edu (Robert Dewar) wrote:

>Can I do this implementation below, legally and portably?
>
>function "+" (L, R : Heading) return Heading is
>   Sum : constant Heading'Base := L + R;
>begin
>   if Sum > Heading'Last then
>      return Sum - Heading'Last;
>   else
>      return Sum;
>   end if;
>end;
>
>  No you can't, because there is no guarantee that the range of Heading'Base
>  exceeds the range of Heading. If you find this a "bummer" you have some
>  fundamental misconceptions about the type system of Ada.

Yes, Robert, that is probably the case.  Which is the reason for the post.

>  What you need to do is to define a local subtype large enough to hold the
>  sum and do conversions appropriately.

OK, I think I've got that part.

But here's another thing I'm confused about.  During the panel discussion
on Friday morning at TRI-Ada '95, Alexandar Stepanov said that he couldn't
do iteration in Ada 83.  What (I think) he wanted to do was to (actively,
not passively) iterate through an array, but to do that, your iteration
index has to fall off the end of the array (that's the termination
condition), the same way as it would it you were iterating through a linked
list (where the pointer would become null).

So I Alex was complaining that if you have (something like)

type AI is range 1 .. 10;
type AT is array (AI) of AC;

The index of an active iterator needs to have the range 1 .. 11, so Alex
said he didn't like Ada because he didn't have that range, and therefore
couldn't do (active) iteration.

So Tuck responded "That's what T'Base is for."

But it would seem that the only thing I can assume about T'Base is that it
has the same range as T, so what did Tuck mean?  How would it be used to
solve Alex' problem?

So what is T'Base for, exactly?  If, to guarantee a minimum range in which
to do intermediate calculations,  I must explicitly declare a (sub) type
with that range, and then subtype off of that to get the type I really care
about, what does T'Base buy me?  I can already do this in Ada 83, so why
was it added to the language, if I have to manually declare a supertype
anyway?  It seems I can't assume anything about its range (just that it
includes T), so why would I ever declare an object of the type T'Base?

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




  reply	other threads:[~1997-01-30  0:00 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-01-26  0:00 Question about base types Matthew Heaney
1997-01-27  0:00 ` Mats Weber
1997-01-28  0:00   ` Robert A Duff
1997-01-29  0:00   ` Robert Dewar
1997-01-27  0:00 ` Robert A Duff
1997-01-30  0:00   ` Matthew Heaney
1997-01-30  0:00     ` Matthew Heaney
1997-01-30  0:00     ` Robert Dewar
1997-01-30  0:00       ` Matthew Heaney [this message]
     [not found]     ` <EACHUS.97Feb3221558@spectre.mitre.org>
     [not found]       ` <dewar.855063927@merv>
     [not found]         ` <EACHUS.97Feb6145918@spectre.mitre.org>
     [not found]           ` <dewar.855276722@merv>
1997-02-07  0:00             ` Mats Weber
1997-02-08  0:00               ` Robert Dewar
1997-02-10  0:00                 ` Mats Weber
1997-02-11  0:00                   ` Robert Dewar
     [not found]         ` <32FB45D4.2160@watson.ibm.com>
1997-02-10  0:00           ` Robert Dewar
1997-02-08  0:00   ` Robert Dewar
1997-02-09  0:00     ` Matthew Heaney
1997-02-09  0:00       ` Robert Dewar
1997-02-09  0:00         ` Matthew Heaney
1997-02-10  0:00           ` Robert Dewar
1997-02-10  0:00       ` Larry Kilgallen
1997-02-11  0:00   ` Robert I. Eachus
1997-02-12  0:00     ` Robert Dewar
1997-01-28  0:00 ` Robert I. Eachus
1997-01-28  0:00   ` Mats Weber
1997-01-29  0:00 ` Robert I. Eachus
1997-01-30  0:00   ` Robert A Duff
replies disabled

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