From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-0.5 required=3.0 tests=BAYES_05 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 16 Sep 92 05:24:46 GMT From: munnari.oz.au!yoyo.aarnet.edu.au!huon.itd.adelaide.edu.au!cs.adelaide.edu .au!andrewd@uunet.uu.net (Andrew Dunstan) Subject: Re: Novice Question On Generics Message-ID: <196geuINNacl@huon.itd.adelaide.edu.au> List-Id: In article <1992Sep15.184345.12197@saifr00.cfsat.honeywell.com>, lam@saifr00.cf sat.honeywell.com (Josh Lam) writes: [sorry for long repost - I'v cut it down a fair bit] |> with Queue with Queue |> package A is package B is |> ... ... |> type A_record is type B_record is |> record record |> ... ... |> end record end record |> package my_QA is new Queue(A_record); package my_QB is new Queue(B_re cord); |> ... ... |> Run_Proc(X : A_record); Run_Proc(Y : B_record); |> ... ... |> end A; end B; |> |> Now the Run_Proc procedures for both packages will look like: |> |> Run_Proc(X : A_record) is Run_Proc(Y : B_record) is |> begin begin |> my_QA.enqueue(X); my_QB.enqueue(Y); |> end Run_Proc; end Run_Proc; |> |> Basically, they contain the same functionality. In this example, I only |> wrote one line of code for simplicity of illustration, in reality, there |> could be more lines of code but same functionality. The only difference |> is the queue instantiations my_QA and my_QB. |> |> 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 |> and my_QB ie they are private members to A and B respectively and Run_Proc i s |> the only interface to the outside world. ie, The user only need to type |> A.Run_Proc(X) or B.Run_Proc(Y). I think this is what you want: with queue; generic type x is private; package run_proc_pack is -- following line might be in the body, if queue not needed to be public package rpq is new queue(x); procedure run_proc(a : x); end run_proc_pack; package body run_proc_pack is procedure run_proc(a: x) is begin rpq.enqueue(a); end run_proc; end run_proc_pack; ... package a_run is new run_proc_pack(a_record); package b_run is new run_proc_pack(b_record); ... a_run.run_proc(a_rec); ... without knowing more about what you are actually trying to do, it is hard to tell if this is what you really want. -- ####################################################################### # Andrew Dunstan # There's nothing good or bad # # Department of Computer Science # but thinking makes it so. # # University of Adelaide # # # South Australia # - Shakespeare # # net: andrewd@cs.adelaide.edu.au # # #######################################################################