home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / ada / 2627 < prev    next >
Encoding:
Text File  |  1992-09-15  |  2.5 KB  |  76 lines

  1. Newsgroups: comp.lang.ada
  2. Path: sparky!uunet!wupost!zaphod.mps.ohio-state.edu!sdd.hp.com!uakari.primate.wisc.edu!aplcen.apl.jhu.edu!ddsdx2.jhuapl.edu!dlc
  3. From: dlc@ddsdx2.jhuapl.edu (Dave Collard x7468)
  4. Subject: Re: Novice Question On Generics
  5. Message-ID: <1992Sep16.001718.12811@aplcen.apl.jhu.edu>
  6. Sender: news@aplcen.apl.jhu.edu (USENET News System)
  7. Organization: Johns Hopkins University
  8. References: <1992Sep15.184345.12197@saifr00.cfsat.honeywell.com>
  9. Distribution: usa
  10. Date: Wed, 16 Sep 92 00:17:18 GMT
  11. Lines: 63
  12.  
  13. In <1992Sep15.184345.12197@saifr00.cfsat.honeywell.com> lam@saifr00.cfsat.honeywell.com (Josh Lam) writes:
  14.  
  15. >I have a generic package Queue that has the function enqueue.
  16.  
  17. >This generic package is 'with' into two packages A and B that looks
  18. >like:
  19.  
  20. >with Queue                                with Queue
  21. >package A  is                             package B is 
  22.  
  23. > ...                                      ...
  24.  
  25. >Question:
  26. >Is there a way to write a generic procedure Run_Proc that the two packages 
  27. >A and B can use?   Note that the user *does not* need to know my_QA 
  28.  
  29. generic
  30.   type Queue_Item is private;
  31.   with procedure Enqueue(Item : in Queue_Item);
  32. procedure Run_Proc is
  33. begin
  34.   Enqueue(Queue_Item);
  35. end Run_Proc;
  36.  
  37. with Run_Proc;                           with Run_Proc;
  38. with Queue;                              with Queue;
  39. package A is                             package B is
  40.   type A_Rec is record...                  type B_Rec is record...
  41.   end record;                              end record;
  42.   
  43.   package A_Queue is new Queue(A_Rec);     package B_Queue is new
  44.                                              Queue(B_Rec);
  45.  
  46.   procedure A_Run_Proc is new              package B_Run_Proc is new
  47.     Run_Proc(A_Rec, A_Queue.Enqueue);        Run_Proc(B_Rec,B_Queue.Enqueue);
  48.  
  49.   ...                                      ...
  50.  
  51. end A;                                   end B;
  52.  
  53. BUT it is a pain *if* Run_Proc uses many procedures from
  54. Queue.  Each routine from the queue package needs to be
  55. a generic parameter to the Run_Proc (generic) routine.
  56.  
  57. In Ada 9X, you will be able to instantiate a routine or
  58. package with an instantiation of another generic package
  59. which will make the whole idea of generics much better.
  60. So you will be able to to something like this:
  61.  
  62. generic
  63.   with Some_Instantion_Of the generic Queue package; -- I dunno the syntax
  64. procedure Run_Proc(Item : Some_Instantiation_Of.Item) is
  65. begin
  66.   SIO.Enqueue(Item);
  67.   SIO.Dequeue(Item);
  68.   SIO.Do_Anything_in_the_generic_package(Item);
  69. end;
  70.  
  71. --Thor
  72. collard@capsrv.jhuapl.edu
  73. dlc@ddsdx2.jhuapl.edu
  74.  
  75.  
  76.