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 19:16:33 PST Path: nntp.gmd.de!xlink.net!slsv6bt!slbh01.bln.sel.alcatel.de!rcvie!Austria.EU.net!EU.net!howland.reston.ans.net!europa.eng.gtefsd.com!MathWorks.Com!blanket.mitre.org!linus.mitre.org!linus!mbunix!eachus From: eachus@spectre.mitre.org (Robert I. Eachus) Newsgroups: comp.lang.ada Subject: Re: generics using generics (long) Date: 7 Sep 94 09:38:51 Organization: The Mitre Corp., Bedford, MA. Message-ID: References: NNTP-Posting-Host: spectre.mitre.org In-reply-to: skip@taygeta.oc.nps.navy.mil's message of Tue, 6 Sep 1994 23:37:27 GMT Date: 1994-09-07T09:38:51+00:00 List-Id: Try this: -- A Generic 1-D floating point array type generic type Real_Number is digits <>; package G_1D_Array is type One_D_Array is array(INTEGER range<>) of Real_Number; type One_D_Array_Handle is access One_D_Array; -- then a bunch of procedure specifications for I/O and -- reallocating the array on the fly, the usual kind of stuff such as... function Allocate(Arr: One_D_Array) return One_D_Array_Handle; end G_1D_Array; -- A Generic Package for fast Hartley transforms, intended to work -- with any float type generic type Real_Number is digits <>; type FHT_Array is array (Integer range <>) of Real_Number; type FHT_Handle is access FHT_Array; with function Allocate(Arr: FHT_Array) return FHT_Handle is <>; -- and so on to match G_1D_Array... package Hartley is procedure Normalize(Fx : FHT_Handle); procedure FHT(Fx : FHT_Handle ); end Hartley; with Hartley, G_1D_Array; procedure FHT_Main is type Real is new Long_Float; package Real_Vector is new G_1D_Array(Real); use Real_Vector; -- needed to make the line below work right. package Real_Hartley is new Hartley(Real,One_D_Array,One_D_Array_Handle); Fx: Real_Vector.One_D_Array_Handle; -- ...etc... begin -- code to do lots of things with the 1D Array fx, among -- them calculating its Hartley transform. null; end FHT_Main; Ada9X can make things cleaner with package parameters, but this should do the job. And yes I agree that the "tricks" that are needed to make things work should be taught. However, to my knowledge no one has ever taught a course devoted to the use of generics in Ada 83, and this really needs to be a separate course taught six months of using the "Pascal Superset" of Ada 83. Maybe with Ada 9X someone will put together such a couse as a complement to an Ada and OOP course. (Generics should be IMHO taught first, but with Ada 9X generics are a lot richer...) -- Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is...