comp.lang.ada
 help / color / mirror / Atom feed
* LLQ: Scope and child package names
@ 2000-08-10  0:00 Ted Dennison
  2000-08-11  0:00 ` Robert A Duff
  0 siblings, 1 reply; 2+ messages in thread
From: Ted Dennison @ 2000-08-10  0:00 UTC (permalink / raw)


My compiler's giving me some suprising (to my small mind) results in
this area, so I'd like to find out what the actual rules are in this
area.

Say I have two child packages, one of which "with"s the other. Let's
further stipulate that the name of the with-ee's parent happens to be
the same as the name of the with-or. For example:

package Foo.Utility is
   type Instance is...
...
end Foo.Utility;

with Foo.Utility;

package Facility.Foo is
...
   type Instance is new Foo.Utility.Instance;
end Facility.Foo;

My compiler gacks at this, saying Utility is not found in Foo. I'm
guessing the problem is that "Foo" inside of Facility.Foo is a shorthand
for Facility.Foo, hiding any "Foo" package hierarchy I may have with'ed.
Is that right?

Question 2:

It just so happened that I had a rename for the with-ee parent around.
So I tried using that, expecting failure becuase I had no such rename
for the child package. But to my suprise, it worked! Eg:

package Executive_Foo renames Foo;

with Executive_Foo.Utility;

package Facility.Foo is
...
   type Instance is new Executive_Foo.Utility.Instance;
end Facility.Foo;

This compiled happily. So a rename of a package effectively acts as a
rename for all its children too?

--
T.E.D.

http://www.telepath.com/~dennison/Ted/TED.html


Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: LLQ: Scope and child package names
  2000-08-10  0:00 LLQ: Scope and child package names Ted Dennison
@ 2000-08-11  0:00 ` Robert A Duff
  0 siblings, 0 replies; 2+ messages in thread
From: Robert A Duff @ 2000-08-11  0:00 UTC (permalink / raw)


Ted Dennison <dennison@telepath.com> writes:

> My compiler's giving me some suprising (to my small mind) results in
> this area, so I'd like to find out what the actual rules are in this
> area.
> 
> Say I have two child packages, one of which "with"s the other. Let's
> further stipulate that the name of the with-ee's parent happens to be
> the same as the name of the with-or. For example:
> 
> package Foo.Utility is
>    type Instance is...
> ...
> end Foo.Utility;
> 
> with Foo.Utility;
> 
> package Facility.Foo is
> ...
>    type Instance is new Foo.Utility.Instance;
> end Facility.Foo;
> 
> My compiler gacks at this, saying Utility is not found in Foo. I'm
> guessing the problem is that "Foo" inside of Facility.Foo is a shorthand
> for Facility.Foo, hiding any "Foo" package hierarchy I may have with'ed.
> Is that right?

Yes.

Child packages behave (more or less) as if they were physically nested
in their parent.  Imagine that you had written these packages physically
nested, and then imagine which Foo hides which other Foo where.  Make
sense?

Eg:

procedure Main is
    package Foo is
        package Utility 
    ...etc

> Question 2:
> 
> It just so happened that I had a rename for the with-ee parent around.
> So I tried using that, expecting failure becuase I had no such rename
> for the child package. But to my suprise, it worked! Eg:
> 
> package Executive_Foo renames Foo;
> 
> with Executive_Foo.Utility;
> 
> package Facility.Foo is
> ...
>    type Instance is new Executive_Foo.Utility.Instance;
> end Facility.Foo;
> 
> This compiled happily. So a rename of a package effectively acts as a
> rename for all its children too?

There's nothing special about children when it comes to renaming.  If
you have a name for a package, you can refer to stuff in the package if
that stuff is visible, by saying Package_Name.Whatever.  It doesn't
matter whether Package_Name is a renaming or not.  And it doesn't matter
whether Whatever is a child package, or a nested package, or an integer
type nested in the package, or anything else.  The only thing special is
that children aren't visible unless with'ed.

- Bob




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2000-08-11  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-08-10  0:00 LLQ: Scope and child package names Ted Dennison
2000-08-11  0:00 ` Robert A Duff

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