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,16b1ef91d331648c X-Google-Attributes: gid103376,public From: "Matthew Heaney" Subject: Re: Barnes vs. Dewar Date: 1999/08/27 Message-ID: <37c6a288@news1.us.ibm.net>#1/1 X-Deja-AN: 517810339 Content-transfer-encoding: 7bit References: <37C66E08.16DB@dera.gov.uk> X-Trace: 27 Aug 1999 14:36:56 GMT, 129.37.62.206 Organization: Global Network Services - Remote Access Mail & News Services X-Notice: should be reported to postmaster@ibm.net Content-Type: text/plain; charset="US-ASCII" Mime-version: 1.0 Newsgroups: comp.lang.ada X-Complaints-To: postmaster@ibm.net Date: 1999-08-27T00:00:00+00:00 List-Id: In article <37C66E08.16DB@dera.gov.uk> , Anton Gibbs wrote: > package Tracked_Things is > > type Identity_Controlled is abstract tagged private; > > private > > type Identity_Controlled is abstract new Controlled with > record > Identity_Number : Integer; > end record; > > procedure Initialize( X : in Identity_Controlled ); > -- etc. > > end Tracked_Things; > > package Tracked_Things.User_View is > > type Thing is new Identity_Controlled with > record > UU : Integer; > end record; > > end Tracked_Things.User_View; > > [There are few with/use clauses implied here]. > > Page 287, third paragraph from the end, last sentance reads: > > "We also declare Initialize, Adjust and Finalize in the private part > and so they are also hidden from the user." That is the proper thing to do. Controlled-ness for a type should be completely hidden from clients. > Clearly, these operations are expected to be inherited for the extended > type `Thing' in child package `Tracked_Things.User_View'. Yes, they are indeed inherited, but only for a private view. A private view of Thing is o the body of Tracked_Thing.User_View o anywhere in a private child of Tracked_Thing.User_View o the private part of the spec of a public child of Tracked_Thing.User_View, and its body > Well, when I tried a similar thing with the GNAT compiler it threw it > out complaining that: > > "Initialize" is not a visible entity of "User_View" But, are you sure you didn't try to do this: with Tracked_Thing.User_View; use Tracked_Thing.User_View; procedure Op is O : Thing; begin Initialize (O); end Op; This is of course illegal, because Op isn't a private view of Thing. Try this instead: private procedure Tracked_Thing.User_View.Op; procedure Tracked_Thing.User_View.Op is O : Thing; begin Initialize (O); end; This should work, but I don't have a compiler handy to test it. > After the usual agony with the LRM, I eventually had to agree. I do not > think that the child package `Tracked_Things.User_View' is entitled to > see `Initialize' in the private part of its parent and so it cannot be > inherited. If you move `Initialize' to the visible part it all works > fine. Not quite right. Only the public part of Tracked_Things.User_View is not allowed to see Initialize. The operations Init, Final, and Adj are indeed inherited, and you can see them in the private part of the spec of Tracked_Things.User_View, and in its body. Try this: package Tracked_Things.User_View is type Thing is new Identity_Controlled with record UU : Integer; end record; private procedure Initialize (O : in out Thing); -- override; should compile OK end Tracked_Things.User_View; or try this: package body Tracked_Things.User_View is O : Thing; begin Initialize (O); -- visible, because body is a private view end; > So who is right Barnes or Dewar ? Barnes is right. If you tried to call Initialize from a public view, then Dewar is also correct. > More to the point, what is the correct way to achieve the desired level > of visibility (ie. `Tracked_Things.User_View.Initialize' visible > but `Tracked_Things.Initialize' not) ? This doesn't make any sense. The operation Initialize is private for ALL types in the class whose root is Identity_Controlled, including Thing. You can NEVER call Initialize (Object_Of_Type_Thing) from a public view. > Thanks for any clues. If you want to have a public operation for Thing that does some kind of initialization (maybe even implement it by calling the controlled operation called Initialize), then you're going to have to give the operation some other name. package Tracked_Things.User_View is type Thing is new Identity_Controlled with record UU : Integer; end record; procedure Reset (O : in out Thing); end Tracked_Things.User_View; package body Tracked_Things.User_View is procedure Reset (O : in out Thing) is begin Initialize (O); -- should be legal end; end Tracked_Things.User_View; -- Matt It is impossible to feel great confidence in a negative theory which has always rested its main support on the weak points of its opponent. Joseph Needham, "A Mechanistic Criticism of Vitalism"