From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.7 required=5.0 tests=BAYES_00,INVALID_DATE, MSGID_SHORT,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!husc6!m2c!wpi!wpi.wpi.edu!tfrancis From: tfrancis@wpi.wpi.edu (Krishan M Nainani) Newsgroups: comp.lang.ada Subject: Summary of "Passing procedures as parameters" Message-ID: <3350@wpi.wpi.edu> Date: 24 Jul 89 20:58:46 GMT Sender: tfrancis@wpi.wpi.edu Reply-To: tfrancis@wpi.wpi.edu (Krishan M Nainani) Distribution: usa Organization: Worcester Polytechnic Institute, Worcester, Mass. List-Id: Hi Netters, Sometime ago I wasn't quite sure how to pass procedures as parameters in Ada and so I posted some mail to this newsgroup and I got a variety of replies. Some people said that this was not possible whereas others said that it was possible via generic instantiation. However, the most detailed reply came from Mr. Arny Engelson who was very kind to give me the following 3 ways: > I do not know of an easy way to do exactly what you want (pass >procedures and functions as parameters to a subprogram) in Ada, but >there are several ways to do something similar to what you want. > First, you can pass the 'address of a subprogram as the parameter, >and then call a system routine to invoke the subprogram. Whether or >not you can do this easily depends on the Ada/system_call interface >on your system, and is not portable. > Second, you can convert the subprogram you want to invoke into a >task (type), and pass a pointer to the task as the parameter. This >works OK, but adds some overhead and means you need to rendezvous >with the task to pass it the necessary parameters after it is invoked. > Third, you can use generics. Whether this is a viable solution >for you depends on the particular situation you are facing. But, you >can both declare a generic subprogram, and also pass subprograms to >a generic subprogram. > There may be other ways as well; I am not an expert in this topic. >If you hear of any other useful ideas, please forward them (or rather >post a summary to the net). I would be very interested in hearing >what else may be done, and I'm sure others would be also. > - Arny Engelson att!wayback!arny For those who are interested, I ended up using a combination of tasks and generic procedure passing. I had to use task types in order to store the information in a record structure and the generic procedure passing was used to pass the procedures to the generic package that executed the procedures. For example, my (the user's) generic instantiation was: package xxx is new xyz(proc1,proc2); -- where proc1,proc2 were defined -- earlier by the user The package xyz took the 2 procedures and, using a task type with 2 entries (1 for each procedure), it executed each procedure within each entry so that the accept statement for each entry only contained the procedure name. Thanx to everyone who replied to me. Krishan Nainani (tfrancis@wpi.wpi.edu)