* [Q] Problem with Array Concatenation? @ 1997-07-08 0:00 John McCabe 1997-07-08 0:00 ` Michael Quinn ` (2 more replies) 0 siblings, 3 replies; 9+ messages in thread From: John McCabe @ 1997-07-08 0:00 UTC (permalink / raw) Hi, I would appreciate confirmation on whether the following piece of code is legal Ada 83, and what the effect should be (obviously I haven't bothered with Text_IO for outputting results, but what should happen when I compile this?). ----------- procedure Test is type Arr_Type is array (1 .. 100) of Integer; Src_Array : Arr_Type; Dst_Array : Arr_Type; begin for Index in 1 .. 100 loop Src_Array (Index) := Index; end loop; Dst_Array := (others => 0); Dst_Array := Src_Array (51 .. 100) & Src_Array (1 .. 50); end Test; ----------- Thanking you in advance. Best Regards John McCabe <john@assen.demon.co.uk> ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Q] Problem with Array Concatenation? 1997-07-08 0:00 [Q] Problem with Array Concatenation? John McCabe @ 1997-07-08 0:00 ` Michael Quinn 1997-07-09 0:00 ` Tucker Taft 1997-07-10 0:00 ` Matthew Heaney 2 siblings, 0 replies; 9+ messages in thread From: Michael Quinn @ 1997-07-08 0:00 UTC (permalink / raw) Concatenation of arrays is valid in Ada 83. Your code should work. -- Michael T. Quinn sent replies to : mtquinn@hom.net John McCabe <john@assen.demon.co.uk> wrote in article <33c280c8.418253@news.demon.co.uk>... > Hi, > > I would appreciate confirmation on whether the following piece of code > is legal Ada 83, and what the effect should be (obviously I haven't > bothered with Text_IO for outputting results, but what should happen > when I compile this?). > > ----------- > procedure Test is .. stuff deleted ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Q] Problem with Array Concatenation? 1997-07-08 0:00 [Q] Problem with Array Concatenation? John McCabe 1997-07-08 0:00 ` Michael Quinn @ 1997-07-09 0:00 ` Tucker Taft 1997-07-10 0:00 ` Matthew Heaney 2 siblings, 0 replies; 9+ messages in thread From: Tucker Taft @ 1997-07-09 0:00 UTC (permalink / raw) John McCabe (john@assen.demon.co.uk) wrote: : I would appreciate confirmation on whether the following piece of code : is legal Ada 83, and what the effect should be (obviously I haven't : bothered with Text_IO for outputting results, but what should happen : when I compile this?). This is legal Ada 83, but will raise Constraint_Error at run-time, because the result of the concatenation (before "sliding" happens) has a high bound of 150, which is outside the index subtype (which goes only from 1 up to 100) -- see paragraph RM83 4.5.3(6). In Ada 95, it would do the "expected," and give you an array with the values (51,52, ...,100,1,2,..., 50). This is thanks to paragraph RM95 4.5.3(6), which specially handles the case when the array type was defined by a constrained_array_definition, and essentially "pre-slides" the result, so the result of the concatenation has the bounds 1..100 rather than 51..150. This is one of those little annoyances from Ada 83 which we "fixed" in Ada 95. (I quote "fixed" because there are probably still those who find the Ada 83 approach in some sense to have more "purity of essence" -- aka POE for those Dr. Strangelove fans.) : ----------- : procedure Test is : type Arr_Type is array (1 .. 100) of Integer; : Src_Array : Arr_Type; : Dst_Array : Arr_Type; : begin : for Index in 1 .. 100 loop : Src_Array (Index) := Index; : end loop; : Dst_Array := (others => 0); : Dst_Array := Src_Array (51 .. 100) & Src_Array (1 .. 50); : end Test; : ----------- : Thanking you in advance. : Best Regards : John McCabe <john@assen.demon.co.uk> -- -Tucker Taft stt@inmet.com http://www.inmet.com/~stt/ Intermetrics, Inc. Burlington, MA USA ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Q] Problem with Array Concatenation? 1997-07-08 0:00 [Q] Problem with Array Concatenation? John McCabe 1997-07-08 0:00 ` Michael Quinn 1997-07-09 0:00 ` Tucker Taft @ 1997-07-10 0:00 ` Matthew Heaney 1997-07-11 0:00 ` Tucker Taft 2 siblings, 1 reply; 9+ messages in thread From: Matthew Heaney @ 1997-07-10 0:00 UTC (permalink / raw) In article <33c280c8.418253@news.demon.co.uk>, john@assen.demon.co.uk (John McCabe) wrote: >procedure Test is > type Arr_Type is array (1 .. 100) of Integer; > > Src_Array : Arr_Type; > Dst_Array : Arr_Type; >begin > for Index in 1 .. 100 loop > Src_Array (Index) := Index; > end loop; > Dst_Array := (others => 0); > > Dst_Array := Src_Array (51 .. 100) & Src_Array (1 .. 50); >end Test; As Tuck pointed out, the concatenation will raise Constraint_Error, even though this is a legal Ada program. But even in Ada 83, there is a simple fix: make the array type unconstrained: declare type AT is array (Positive range <>) of Integer; SA : AT (Positive range 1 .. 100); DA : AT (SA'Range); begin for Index in SA'Range loop SA (Index) := Index; end loop; DA := SA (51 .. 100) & SA (1 .. 50); end; There's another way to make the fix, by manually sliding the initial substring: declare type AT is array (Positive range 1 .. 100) of Integer; SA : AT; DA : AT; subtype Slided is AT (1 .. 50); begin ... DA := Slided (SA (51 .. 100)) & SA (1 .. 50); end; In Ada 83 the 2nd substring will be automatically slided. - Matt -------------------------------------------------------------------- Matthew Heaney Software Development Consultant <mailto:matthew_heaney@acm.org> (818) 985-1271 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Q] Problem with Array Concatenation? 1997-07-10 0:00 ` Matthew Heaney @ 1997-07-11 0:00 ` Tucker Taft 1997-07-11 0:00 ` Matthew Heaney ` (2 more replies) 0 siblings, 3 replies; 9+ messages in thread From: Tucker Taft @ 1997-07-11 0:00 UTC (permalink / raw) Matthew Heaney (mheaney@ni.net) wrote: : ... : There's another way to make the fix, by manually sliding the initial substring: : declare : type AT is array (Positive range 1 .. 100) of Integer; : SA : AT; : DA : AT; : subtype Slided is AT (1 .. 50); Now *this* is not legal Ada (83 or 95). You can't re-constrain a constrained array (sub)type. : begin : ... : DA := Slided (SA (51 .. 100)) & SA (1 .. 50); : end; : In Ada 83 the 2nd substring will be automatically slided. Only if you can convince the compiler to accept the declaration for "Slided" (sic). By the way, I prefer the word "slid" ;-). : - Matt : -------------------------------------------------------------------- : Matthew Heaney : Software Development Consultant : <mailto:matthew_heaney@acm.org> : (818) 985-1271 -- -Tucker Taft stt@inmet.com http://www.inmet.com/~stt/ Intermetrics, Inc. Burlington, MA USA ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Q] Problem with Array Concatenation? 1997-07-11 0:00 ` Tucker Taft @ 1997-07-11 0:00 ` Matthew Heaney 1997-07-13 0:00 ` Keith Thompson 1997-07-13 0:00 ` Robert A Duff 2 siblings, 0 replies; 9+ messages in thread From: Matthew Heaney @ 1997-07-11 0:00 UTC (permalink / raw) In article <ED611s.5yM.0.-s@inmet.camb.inmet.com>, stt@houdini.camb.inmet.com (Tucker Taft) wrote: >: SA : AT; >: DA : AT; >: subtype Slided is AT (1 .. 50); > >Now *this* is not legal Ada (83 or 95). You can't re-constrain >a constrained array (sub)type. Oops! Tuck is, of course, correct. I guess the compiler in my head has a few bugs, eh? If you're stuck with a constrained array type (perhaps it's a global type), then you can still do the sliding solution locally by casting the array slice into locally declared unconstrained array type: type AT is array (1 .. 100) of T; ... type Unconstrained_AT is array (Positive range <>) of T; SA, DA : AT; subtype Slid is Unconstrained_AT (1 .. 50); begin ... DA := AT (Slid (SA (51 .. 100)) & Slid (SA (1 .. 50))); Won't that work? -------------------------------------------------------------------- Matthew Heaney Software Development Consultant <mailto:matthew_heaney@acm.org> (818) 985-1271 ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Q] Problem with Array Concatenation? 1997-07-11 0:00 ` Tucker Taft 1997-07-11 0:00 ` Matthew Heaney @ 1997-07-13 0:00 ` Keith Thompson 1997-07-13 0:00 ` Robert A Duff 2 siblings, 0 replies; 9+ messages in thread From: Keith Thompson @ 1997-07-13 0:00 UTC (permalink / raw) In <ED611s.5yM.0.-s@inmet.camb.inmet.com> stt@houdini.camb.inmet.com (Tucker Taft) writes: > Matthew Heaney (mheaney@ni.net) wrote: > : ... > : There's another way to make the fix, by manually sliding the initial substring: > > : declare > : type AT is array (Positive range 1 .. 100) of Integer; > > : SA : AT; > : DA : AT; > : subtype Slided is AT (1 .. 50); > > Now *this* is not legal Ada (83 or 95). You can't re-constrain > a constrained array (sub)type. If Ada 95 hadn't restricted the 'Base attribute to apply only to scalar subtypes, you could declare: subtype Slided is AT'Base (1 .. 50); -- or Slid, if you prefer (Some, but not all, Ada 95 compilers do support this.) Of course, there's also the minor problem that AT is a reserved word. -- Keith Thompson (The_Other_Keith) kst@sd.aonix.com <http://www.aonix.com> <*> TeleSo^H^H^H^H^H^H Alsy^H^H^H^H Thomson Softw^H^H^H^H^H^H^H^H^H^H^H^H^H Aonix 5040 Shoreham Place, San Diego, CA, USA, 92122-5989 "Zathras warn Zathras, but Zathras never listen to Zathras." -- Zathras ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Q] Problem with Array Concatenation? 1997-07-11 0:00 ` Tucker Taft 1997-07-11 0:00 ` Matthew Heaney 1997-07-13 0:00 ` Keith Thompson @ 1997-07-13 0:00 ` Robert A Duff 1997-07-13 0:00 ` John McCabe 2 siblings, 1 reply; 9+ messages in thread From: Robert A Duff @ 1997-07-13 0:00 UTC (permalink / raw) In article <ED611s.5yM.0.-s@inmet.camb.inmet.com>, Tucker Taft <stt@houdini.camb.inmet.com> wrote: >Matthew Heaney (mheaney@ni.net) wrote: >: ... >: There's another way to make the fix, by manually sliding the initial substring: > >: declare >: type AT is array (Positive range 1 .. 100) of Integer; > >: SA : AT; >: DA : AT; >: subtype Slided is AT (1 .. 50); > >Now *this* is not legal Ada (83 or 95). You can't re-constrain >a constrained array (sub)type. Heh, heh. You can't call a type "AT", because that's a reserved word. ;-) (And, as Tucker points out, it ain't legal English, either -- "slided" ain't a word.) - Bob ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Q] Problem with Array Concatenation? 1997-07-13 0:00 ` Robert A Duff @ 1997-07-13 0:00 ` John McCabe 0 siblings, 0 replies; 9+ messages in thread From: John McCabe @ 1997-07-13 0:00 UTC (permalink / raw) bobduff@world.std.com (Robert A Duff) wrote: <..snip..> >Heh, heh. You can't call a type "AT", because that's a reserved word. >;-) (And, as Tucker points out, it ain't legal English, either -- >"slided" ain't a word.) And "ain't" is??? Best Regards John McCabe <john@assen.demon.co.uk> ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~1997-07-13 0:00 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 1997-07-08 0:00 [Q] Problem with Array Concatenation? John McCabe 1997-07-08 0:00 ` Michael Quinn 1997-07-09 0:00 ` Tucker Taft 1997-07-10 0:00 ` Matthew Heaney 1997-07-11 0:00 ` Tucker Taft 1997-07-11 0:00 ` Matthew Heaney 1997-07-13 0:00 ` Keith Thompson 1997-07-13 0:00 ` Robert A Duff 1997-07-13 0:00 ` John McCabe
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox