From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d57302f2954365e1 X-Google-Attributes: gid103376,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: Question about base types Date: 1997/01/30 Message-ID: #1/1 X-Deja-AN: 213252872 references: content-type: text/plain; charset=ISO-8859-1 organization: Estormza Software mime-version: 1.0 newsgroups: comp.lang.ada Date: 1997-01-30T00:00:00+00:00 List-Id: In article , 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 (818) 985-1271