comp.lang.ada
 help / color / mirror / Atom feed
From: eachus@spectre.mitre.org (Robert I. Eachus)
Subject: Re: generics using generics (long)
Date: 7 Sep 94 09:38:51
Date: 1994-09-07T09:38:51+00:00	[thread overview]
Message-ID: <EACHUS.94Sep7093851@spectre.mitre.org> (raw)
In-Reply-To: skip@taygeta.oc.nps.navy.mil's message of Tue, 6 Sep 1994 23:37:27 GMT


    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...



       reply	other threads:[~1994-09-07  9:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CvqEyG.nD@taurus.cs.nps.navy.mil>
1994-09-07  9:38 ` Robert I. Eachus [this message]
1994-09-07 16:54 ` generics using generics (long) 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