comp.lang.ada
 help / color / mirror / Atom feed
From: Robert Dewar <dewar@gnat.com>
Subject: Re: Common ancestor (visibility rules)
Date: 2000/03/29
Date: 2000-03-29T00:00:00+00:00	[thread overview]
Message-ID: <8bskgp$ctu$1@nnrp1.deja.com> (raw)
In-Reply-To: 8bsgpf$96f$1@nnrp1.deja.com

In article <8bsgpf$96f$1@nnrp1.deja.com>,
  dmitry6243@my-deja.com wrote:

> In article <8bq726$lo8$1@nnrp1.deja.com>,
> Robert Dewar <robert_dewar@my-deja.com> 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.




  reply	other threads:[~2000-03-29  0:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-03-28  0:00 Common ancestor (visibility rules) dmitry6243
2000-03-28  0:00 ` Steve Folly
2000-03-28  0:00 ` Robert Dewar
2000-03-29  0:00   ` dmitry6243
2000-03-29  0:00     ` Robert Dewar [this message]
2000-03-29  0:00       ` dmitry6243
2000-03-30  0:00         ` Robert Dewar
2000-03-30  0:00           ` dmitry6243
2000-03-30  0:00             ` Tucker Taft
2000-03-31  0:00               ` dmitry6243
2000-04-01  0:00               ` Robert Dewar
2000-04-01  0:00               ` Robert Dewar
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox