From: eachus@mitre-bedford.arpa (Robert I. Eachus)
Subject: Re: null unconstrained arrays vs generic formal types
Date: 23 Sep 93 23:51:54 GMT [thread overview]
Message-ID: <EACHUS.93Sep23185154@spectre.mitre.org> (raw)
In article <23SEP199311043613@bambam.gsfc.nasa.gov> nbssal@bambam.gsfc.nasa.gov
(Stephe Leake) writes:
> So, does Ada 9x fix this by relaxing LRM 12.3.4(5)? Does anyone
> have an alternate solution?
It took me a while to recognize why you had a problem. (Even if you
quoted my favorite paragraph number in Ada 83.) Ada 9X retains the
same rule, although you could submit this as a comment on the standard
during the balloting. Of course, the "right" solution might be to
have generic formal subtypes. But I don't think you need any of that.
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_INDE
X_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.
--
Robert I. Eachus
with Standard_Disclaimer;
use Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...
next reply other threads:[~1993-09-23 23:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1993-09-23 23:51 Robert I. Eachus [this message]
-- strict thread matches above, loose matches on Subject: below --
1993-09-24 17:56 null unconstrained arrays vs generic formal types Stephe Leake
1993-09-24 17:50 Stephe Leake
1993-09-23 22:04 Tucker Taft
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox