comp.lang.ada
 help / color / mirror / Atom feed
From: agate!linus!think.com!yale.edu!spool.mu.edu!caen!uakari.primate.wisc.edu! aplcen.apl.jhu.edu!ddsdx2.jhuapl.edu!dlc@ucbvax.Berkeley.EDU  (Dave Collard x74
Subject: Re: Novice Question On Generics
Date: 16 Sep 92 00:17:18 GMT	[thread overview]
Message-ID: <1992Sep16.001718.12811@aplcen.apl.jhu.edu> (raw)

In <1992Sep15.184345.12197@saifr00.cfsat.honeywell.com> lam@saifr00.cfsat.honey
well.com (Josh Lam) writes:

>I have a generic package Queue that has the function enqueue.

>This generic package is 'with' into two packages A and B that looks
>like:

>with Queue                                with Queue
>package A  is                             package B is 

> ...                                      ...

>Question:
>Is there a way to write a generic procedure Run_Proc that the two packages 
>A and B can use?   Note that the user *does not* need to know my_QA 

generic
  type Queue_Item is private;
  with procedure Enqueue(Item : in Queue_Item);
procedure Run_Proc is
begin
  Enqueue(Queue_Item);
end Run_Proc;

with Run_Proc;                           with Run_Proc;
with Queue;                              with Queue;
package A is                             package B is
  type A_Rec is record...                  type B_Rec is record...
  end record;                              end record;
  
  package A_Queue is new Queue(A_Rec);     package B_Queue is new
                                             Queue(B_Rec);

  procedure A_Run_Proc is new              package B_Run_Proc is new
    Run_Proc(A_Rec, A_Queue.Enqueue);        Run_Proc(B_Rec,B_Queue.Enqueue);

  ...                                      ...

end A;                                   end B;

BUT it is a pain *if* Run_Proc uses many procedures from
Queue.  Each routine from the queue package needs to be
a generic parameter to the Run_Proc (generic) routine.

In Ada 9X, you will be able to instantiate a routine or
package with an instantiation of another generic package
which will make the whole idea of generics much better.
So you will be able to to something like this:

generic
  with Some_Instantion_Of the generic Queue package; -- I dunno the syntax
procedure Run_Proc(Item : Some_Instantiation_Of.Item) is
begin
  SIO.Enqueue(Item);
  SIO.Dequeue(Item);
  SIO.Do_Anything_in_the_generic_package(Item);
end;

--Thor
collard@capsrv.jhuapl.edu
dlc@ddsdx2.jhuapl.edu

             reply	other threads:[~1992-09-16  0:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1992-09-16  0:17 agate!linus!think.com!yale.edu!spool.mu.edu!caen!uakari.primate.wisc.edu! [this message]
  -- strict thread matches above, loose matches on Subject: below --
1992-09-16  5:24 Novice Question On Generics Andrew Dunstan
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox