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=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9a2300cb53a6ac87 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-09-07 21:29:35 PST Newsgroups: comp.lang.ada Path: nntp.gmd.de!xlink.net!news.dfn.de!darwin.sura.net!howland.reston.ans.net!gatech!newsxfer.itd.umich.edu!gumby!yale!yale.edu!noc.near.net!inmet!spock!stt From: stt@spock.camb.inmet.com (Tucker Taft) Subject: Re: generics using generics (long) Message-ID: Sender: news@inmet.camb.inmet.com Organization: Intermetrics, Inc. References: Date: Wed, 7 Sep 1994 16:54:53 GMT Date: 1994-09-07T16:54:53+00:00 List-Id: In article , Skip Carter wrote: > I am trying to figure out how to design some generic code to work > with other generics as their parameters but can't figure out a clean way > to do it. > > Here is what I am trying to do: > > >-- A Generic 1-D floating point array type >generic >RealNumber is digits<>; ^^ type > >Package G1DArray is > type 1DArray is array(INTEGER range<>) of RealNumber; > type 1DArrayHandle is access 1DArrray; > > -- then a bunch of procedure specifications > -- for I/O and reallocating the array on the fly, > -- the usual kind of stuff... > >end G1DArray; > > >-- A Generic Package for fast Hartley transforms, >-- intended to work with any float type >with G1DArray; > >generic >Type RealNumber is digits<>; >Type FHT_Array is new G1DArray(RealNumber); -- this is wrong, > -- but it is the kind of thing > -- that I have in mind In Ada 9X, you can import an instance of a generic. This would allow you to replace both of the above formal parameters with the single "formal package" parameter: with package FHT is new G1DArray(<>); use FHT; -- This makes FHT.1DArray and FHT.1DArrayHandle directly visible >Package Hartley is > procedure Normalize(fx : 1DArrayHandle); > procedure FHT( fx : 1DArrayHandle ); >end Hartley; You instantiate Hartley by first instantiating G1DArray, and then passing that instance in an instantiation of Hartley. For example: package Float_Vector is new G1DArray(Float); package Float_Hartley is new Hartley(Float_Vector); >So an application would look like: > >with Hartley, G1DArray > >procedure FHTMAIN is > type Real is new long_float; > > package Real_Vector is new G1DArray( Real ); > > package Real_Hartley is new Hartley(Real,Real_Vector); > -- this is how I'd LIKE to be > -- able to instantiate the package As indicated above, if you use a formal package parameter, this instantiation would be: package Real_Hartley is new Hartley(Real_Vector); > fx : 1DArrayHandle; > > > -- ...etc... > > -- code to do lots of things with the 1D Array fx, > -- among them calculating > -- its hartley transform > >end FHTMAIN; > ... > How do I specify things to work the other way around ? Formal packages were provided in Ada 9X to solve this problem. > Is there is good book out there that teaches Ada idioms, > as opposed to grammar, > that can help with this kind of question ? There are a number of good Ada books that include examples of using Ada. See the comp.lang.ada FAQ (on ajpo.sei.cmu.edu and the EPFL WWW server). Some of them already cover Ada 9X features (e.g. John Barnes 4th edition of "Programming in Ada"). > Everett (Skip) Carter Phone: 408-656-3318 FAX: 408-656-2712 > Naval Postgraduate School INTERNET: skip@taygeta.oc.nps.navy.mil -Tucker Taft stt@inmet.com