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, MSGID_RANDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,84b1828b2b26fc4f X-Google-Attributes: gid103376,public From: Robert Dewar Subject: Re: Common ancestor (visibility rules) Date: 2000/03/29 Message-ID: <8bskgp$ctu$1@nnrp1.deja.com>#1/1 X-Deja-AN: 603790793 References: <8bprin$a37$1@nnrp1.deja.com> <8bq726$lo8$1@nnrp1.deja.com> <8bsgpf$96f$1@nnrp1.deja.com> X-Http-Proxy: 1.0 x33.deja.com:80 (Squid/1.1.22) for client 205.232.38.14 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Wed Mar 29 10:05:20 2000 GMT X-MyDeja-Info: XMYDJUIDrobert_dewar Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.61 [en] (OS/2; I) Date: 2000-03-29T00:00:00+00:00 List-Id: In article <8bsgpf$96f$1@nnrp1.deja.com>, dmitry6243@my-deja.com wrote: > In article <8bq726$lo8$1@nnrp1.deja.com>, > Robert Dewar wrote: > > > No need to invent a new name, it is called Standard > > > > Then package A could be specified as > > > Root.A and A's Foo as Root.A.Foo. > > Yes, "Standard" was actually my first attempt, Well you have got yourself quite confused here. There are two ways of doing things. You either use a USE statement, or you qualify the name. Your original post was about the second attempt, and the proper form is simply Standard.A.Foo; Now if you want to use a USE statement, you have a much simpler form for a-b.adb: with A; use A; separate (B) procedure A is begin Foo; end A; and that of course is perfectly fine, since the "use A" makes Foo visible. > but I tried the following > with Standard.A; use Standard.A; No, that's completely wrong, why, because you can only WITH a library unit, and Standard is NOT a library unit, it is the ancestor of all library units, a library unit is PRECISELY something which is a *child* of standard, and standard is definitely not its own child! > The correct version is: > -------------------- b-a.adb > with A; use Standard.A; No, that is not the correct version (though it is legal). The Standard. prefix here is odd and completely unnecessary in all circumstances in a use clause. > I must say, that the difference is rather subtle. Not subtle at all once you have the right model, which is that there is Standard at the outer level, and then all the library units are children of Standard. > Perhaps compiler should first > search for physical childs of Standard and then in case of > failure, discard the "Standard" prefix, so that: > > with Standard.A; use Standard.A; > > would be correct? No, that would a) be a very confusing rule once you understand things b) be totally unnecessary, since you can always write this as: with A; use A; which is the obvious convenient and useful way to write this. c) would cause confusion and ambiguity as further explored below. The only time you need an explicit prefix of Standard is when you are trying to reference an outer entity of the same name as an inner entity by explicit qualification. In fact this very rarely happens, why? because it is generally very bad style to reuse names this way. In your little example, you are operating in an environment where the code knows that A is a library unit, and intends to use a procedure from A. It is not illegal, but it *is* bad practice and confusing to use this same name A for one of your procedures in this region. By the way, it is under some circumstances legal (though very bad practice to write) with Standard.A; If you really understand things by now, you should be able to figure out the conditions. We can only *with* a library unit, so the above is legal only if there is a library unit Standard and a child Standard.A. Well we learned from above that the Standard that is in the RM is NOT a library unit, but rather the parent of all library units, so the above must imply that there is another Standard that is a library unit. A bit surprisingly, this is allowed, there is nothing illegal about writing a library package of your own: package Standard is ... and a child of it package Standard.A is ... Now this is simply horrible practice, it would be as bad, or perhaps worse than writing package Integer is ... which is also legal but horrible. If you absolutely MUST write a package called Standard, and then you need to reference an entity within this package in a situation where there is am ambiguity similar to your original: with Standard; package body Foo is procedure Standard is begin Standard.Junk; -- call Junk from Standard package end; end; then to deal with the fact that you have hidden the standard you want with the local procedure Standard, you could either use a use clause: with Standard; use Standard; or you could fully qualify: Standard.Standard.Junk; Of course this is perfectly frightful code, due to the atrocious bad choice of Standard in your own code, but it is legal, and should help explain why your suggestion of some special casing for "with Standard" would not work :-) Sent via Deja.com http://www.deja.com/ Before you buy.