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!.POSTED!not-for-mail From: "Alejandro R. Mosteo" Newsgroups: comp.lang.ada Subject: Re: package organization (is this doable?) Date: Mon, 2 Jul 2018 10:23:06 +0200 Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Mon, 2 Jul 2018 08:23:07 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="b6c6c2d4fb577ecc139d0401855a7a4b"; logging-data="8641"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX194Cu/db7xR9dm3M6G2JOHj" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 Cancel-Lock: sha1:oFjLaFwWYCVt3ur5gTmxQabQ0Jc= In-Reply-To: Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:53501 Date: 2018-07-02T10:23:06+02:00 List-Id: On 29/06/2018 21:37, Simon Wright wrote: > "Alejandro R. Mosteo" writes: > >> On 29/06/2018 18:34, Simon Wright wrote: >>> "Alejandro R. Mosteo" writes: >>> >>>> package Lib; -- Root package >>>> >>>> package Lib.Feat_1; -- Some feature >>>> >>>> package Lib.Feat_2; -- Another feature >>>> >>>> private package Lib.Impl; -- Things I want to keep secret, >>>> conceptually they're in the private part of Lib IIUC. >>>> >>>> Am I right that it is impossible for Feat_1 and Feat_2 to communicate >>>> using something that's private in Lib or Lib.Impl? That would mean >>>> exposing those private types in their respective public parts, which >>>> is a no go. >>> >>> Lib.Feat_1 & 2 can see the private part of Lib, and the public part of >>> Lib.Impl. >>> >>> What's wrong with putting stuff in the public part of Lib.Impl? No one >>> outside Lib can see it. >> >> in Lib.Feat_1, doing a "with Lib.Impl" results in error >> "current unit must also be private descendant of Lib". > > In the spec, yes (or, as you say, 'with private', but of course you > can't make anything in the public part of Feat_1 (which is visible to > clients) depend on the private package Impl. > >> I can do (in Feat_1) a "private with Lib.Impl", but then I can use >> these things only in private parts/body of Lib.Feat_1, which are also >> out of bounds for Lib.Feat_2, and viceversa. > > 'with Lib.Impl;' needs to be on Feat_*'s _body_. > > So, put whatever you need Feat_1 to communicate to Feat_2 in Lib's > private part or Impl's public part (remember, it's only public to Lib's > body and Feat_*'s bodies. Thanks, Simon, I think I see a way forward now thanks to your precisions. Álex. > > package Lib is > private > J : Integer := 42; > end Lib; > > package Lib.Feat_1 with Elaborate_Body is > end Lib.Feat_1; > > package Lib.Feat_2 with Elaborate_Body is > end Lib.Feat_2; > > private package Lib.Impl is > K : Integer := 41; > end Lib.Impl; > > with Lib.Impl; > package body Lib.Feat_1 is > A : Integer := J; > U : Integer := Impl.K; > end Lib.Feat_1; > > with Lib.Impl; > package body Lib.Feat_2 is > B : Integer := J; > V : Integer := Impl.K; > end Lib.Feat_2; >