From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 24 Sep 93 17:56:00 GMT From: haven.umd.edu!cs.umd.edu!skates.gsfc.nasa.gov!bambam.gsfc.nasa.gov!nbssal @uunet.uu.net (Stephe Leake) Subject: Re: null unconstrained arrays vs generic formal types Message-ID: <24SEP199312562556@bambam.gsfc.nasa.gov> List-Id: In article , eachus@spectre.mitre.org ( Robert I. Eachus) writes... >In article <23SEP199311043613@bambam.gsfc.nasa.gov> nbssal@bambam.gsfc.nasa.go v (Stephe Leake) writes: > > > > So, does Ada 9x fix this by relaxing LRM 12.3.4(5)? Does anyone > > have an alternate solution? > > ... stuff deleted ... > > In Ada 9X you could make the array type a generic formal derived >type, but the real solution is to reorganize things so that you have a >generic formal package: > > generic > type Index_Base_Type is range <>; > type Element_Type is range <>; -- why not private? > Index_Last: Index_Base_Type; > package Element_Arrays is > subtype ZERO_INDEX_TYPE is range 0 .. Index_Last; > subtype INDEX_TYPE is ZERO_INDEX_TYPE range 1 .. Index_Last; > type INDEX_ARRAY_ELEMENT_TYPE is array (INDEX_TYPE range <>) > of ELEMENT_TYPE; > procedure Element_Get > (Item : out ELEMENT_TYPE; Width : in Text_IO.FIELD); > procedure Element_Put ( > Item : in ELEMENT_TYPE; > Width : in Text_IO.FIELD; > Base : in Text_IO.NUMBER_BASE); > ... > end Element_Arrays; > > package Int_30_Arrays is new Element_Arrays(Integer, Integer, 30); > -- for example... > > Now your generic array IO package looks like: > > with Text_IO; > generic > with package Elem_Arrays is new Element_Arrays(<>); > package Unconstrained_Integer_1D is > use Elem_Arrays; -- depending on your religion. :-) > procedure Get (Item : out INDEX_ARRAY_ELEMENT_TYPE; Last : out ZERO_IND EX_TYPE); > procedure Put (Item : in INDEX_ARRAY_ELEMENT_TYPE); > end Unconstrained_Integer_1D; > > Of course you could put Element_Get and Element_Put elsewhere, but >the principle is that you can pass two subtypes of the same type as >generic parameters in Ada 9X by wrapping them in a generic package >parameter. That's really cool! I would put the Element_Get and Element_Put in a daughter package, so programs that don't need them can't see them. But the ability to group subtypes (and other stuff) in a generic formal package looks really powerful. I guess I'll have to take a hard-copy of the Ada 9X manual home for entertainment reading :-) >-- > > Robert I. Eachus > Stephen Leake NASA Goddard Robotics Lab internet : nbssal@robots.gsfc.nasa.gov