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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,28303942dde70818 X-Google-Attributes: gid103376,public From: Roger_Racine@draper.com (Roger Racine) Subject: Re: Generic using another generic instantiated elsewhere Date: 1998/02/13 Message-ID: #1/1 X-Deja-AN: 324809612 Sender: nntp@news.draper.com (NNTP Master) References: <34E41D3B.474B@cci.de> Organization: Draper Laboratory Newsgroups: comp.lang.ada Date: 1998-02-13T00:00:00+00:00 List-Id: Please pardon the email address. It is bogus. I have never been Spammed before sending a post to this newsgroup. Change Roger_Racine to rracine. In article <34E41D3B.474B@cci.de>, lynch@cci.de wrote: > Hi, > > a colleague of mine, who is fairly new to Ada, came to me with the > following "problem". I'm not quite sure what to suggest to him, so > hopefully you can provide some hints or ideas. > > He has two generic packages, one of which contains a task. > They are both instantiated in the main program. He wants to call > an entry of the task from within the other generic package. > Eg. something like this (not good Ada): > > generic > Some_Type ... > Some_Procedure ... > package Foo is > ... > task Some_Task is > entry do_foo ... > end Some_Task; > end Foo; > > generic > Some_Other_Type ... > Some_Other_Procedure ... > package Bar is > ... > procedure FooBar; > end Bar; > > package body Bar is > procedure FooBar is > begin > ... > My_Foo.Some_Task.do_foo( ... ); > -- somehow call the do_foo entry > -- of the My_Foo instantiation below! > end FooBar; > end Bar; > > procedure Main is > My_Foo is new Foo(); > My_Bar is new Bar(); > begin > ... call FooBar somewhere > end Main; > > > They are using Ada 83 and I doubt this is possible(*). > Should I tell him to "forget the whole thing", or are there other > ways to achieve a similar effect? > > (*) In Ada 95 I guess it would be possible to use a generic formal > package for this, ie. pass My_Foo to the instantiation of Bar? > > Cheers, > Andrew. Add a procedure to the formal parameter list of Bar, and use the entry as the actual parameter. generic Some_Type ... Some_Procedure ... package Foo is ... task Some_Task is entry do_foo ... end Some_Task; end Foo; generic Some_Other_Type ... Some_Other_Procedure ... with procedure Do_Foo(...); -- Note the actual parameter can be an entry package Bar is ... procedure FooBar; end Bar; package body Bar is procedure FooBar is begin ... My_Foo.Some_Task.do_foo( ... ); -- somehow call the do_foo entry -- of the My_Foo instantiation below! end FooBar; end Bar; procedure Main is My_Foo is new Foo(); My_Bar is new Bar( ... ,My_Foo.Some_Task.do_foo); begin ... call FooBar somewhere end Main; Roger Racine Draper Laboratory