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
Date: 24 Sep 93 17:56:00 GMT [thread overview]
Message-ID: <24SEP199312562556@bambam.gsfc.nasa.gov> (raw)
In article <EACHUS.93Sep23185154@spectre.mitre.org>, 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
next reply other threads:[~1993-09-24 17:56 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1993-09-24 17:56 Stephe Leake [this message]
-- strict thread matches above, loose matches on Subject: below --
1993-09-24 17:50 null unconstrained arrays vs generic formal types Stephe Leake
1993-09-23 23:51 Robert I. Eachus
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