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.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Question about generic child packages Date: Thu, 13 Oct 2016 19:19:54 +0200 Organization: Aioe.org NNTP Server Message-ID: References: <08d81628-f1a6-430b-b023-0166a1bedfaa@googlegroups.com> NNTP-Posting-Host: XXXaKfQ6zzC8DMOzOT/pgA.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:32080 Date: 2016-10-13T19:19:54+02:00 List-Id: On 2016-10-13 19:01, Charly wrote: > I have the following question: > Is it possible to have a generic parent package Parent with two (or more) > child packages and than use objects defined in one of the children and use > it in the other one? > Following is a very simple example to show my problem. > In Child_A I defined a function Double and want to use it in Child_B. > It would also be nice to use objects in Child_A, that are defined in B, > not shown in following example. > Of course I can make Child_B a subchild of Child_A, but that is > unsatisfying because it is asymmetric and does not solve the second > part with mutual usage. > > -------------------- > generic > type Data is digits <>; > package Parent is > > end Parent; > > -------------------- > generic > package Parent.Child_A is > > function Double > (X : in Data) > return Data > is > (2.0 * X); > > end Parent.Child_A; > > -------------------- > with Parent.Child_A; > > generic > package Parent.Child_B is > > function Test > (X : in Data) > return Data > is > (2.0 * Parent.Child_A.Double (X)); > > > end Parent.Child_B; It does not work this way because generic children are themselves generic. There is no cascade instantiation of generics in Ada. Therefore you must pass an instance of Parent.Child_A to Parent.Child_B. with Parent.Child_A; generic with package A is new Parent.Child_A; package Parent.Child_B is function Test (X : in Data) return Data is (2.0 * A.Double (X)); end Parent.Child_B; The only way of having a cascade is nested packages. Nested generic packages are proper packages. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de