home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.ada
- Path: sparky!uunet!wupost!zaphod.mps.ohio-state.edu!sdd.hp.com!uakari.primate.wisc.edu!aplcen.apl.jhu.edu!ddsdx2.jhuapl.edu!dlc
- From: dlc@ddsdx2.jhuapl.edu (Dave Collard x7468)
- Subject: Re: Novice Question On Generics
- Message-ID: <1992Sep16.001718.12811@aplcen.apl.jhu.edu>
- Sender: news@aplcen.apl.jhu.edu (USENET News System)
- Organization: Johns Hopkins University
- References: <1992Sep15.184345.12197@saifr00.cfsat.honeywell.com>
- Distribution: usa
- Date: Wed, 16 Sep 92 00:17:18 GMT
- Lines: 63
-
- In <1992Sep15.184345.12197@saifr00.cfsat.honeywell.com> lam@saifr00.cfsat.honeywell.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
-
-
-