From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Generic child units
Date: 16 May 2003 21:00:00 -0400
Date: 2003-05-16T21:00:00-04:00 [thread overview]
Message-ID: <wccissaie0f.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: ba3ved$qbt$1@a1-hrz.uni-duisburg.de
Georg Bauhaus <sb463ba@d2-hrz.uni-duisburg.de> writes:
> Stephen Leake <Stephe.Leake@nasa.gov> wrote:
> : Rodrigo Garc?a <rodrigo.garcia.ARROBA.epfl.ch> writes:
> :
> :> I need some enlightment in this area... Let us suppose that I have two
> :> generic packages declared in separate files and one is the parent of
> :> the other:
> :>
> :> generic
> :> type Elem is private;
> :> package Parent is
> :> type Vector is array (Integer range <>) of Elem;
> :> end Parent;
> :>
> :> generic
> :> package Parent.Child is
> :> subtype Vector2D is Vector (1 .. 2);
> :> end Parent.Child;
> :>
> :> How can I instantiate the child package
> :
> : with Parent.Child;
> : procedure Foo is
> : package Par is new Parent (Elem => Integer);
> : package Chi is new Par.Child;
> : begin
> : ...
> : end Foo;
> :
> : Note that the second instantiation is "Par.Child", not "Parent.Child".
>
> I find it useful to compare to this variation of the packages, at least
> it has shed some light (I think :-/) as far as the instantiation sequence
> is concerned:
Yes, the following example shows what's going on. A child is almost the
same thing as a nested unit.
> generic
> type Elem is private;
> package Parent is
> type Vector is array (Integer range <>) of Elem;
>
> generic
> package Child is
> subtype Vector2D is Vector (1 .. 2);
> end Child;
>
> end Parent;
>
> So, elsewhere, you can't have an instance of child without an instance
> of parent.
Right. Outside Parent, you can't say "new Parent.Child", but you can
say "new Par.Child" if Par is an instance of Parent.
> But you can have an instance of Child in Parent's body. I don't
> know why, exactely, though.
Because when you're inside the generic, you can see Child. If you refer
to Parent inside Parent, you are not referring to a generic, you are
referring to a package -- whatever the "current instance" of Parent is.
> (No wonder that the editors next door tell me that programmers
> are funny people :-)
Indeed.
- Bob
prev parent reply other threads:[~2003-05-17 1:00 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-05-13 17:46 Generic child units
2003-05-13 18:38 ` Stephen Leake
2003-05-13 19:18 ` David C. Hoos
2003-05-14 7:56 `
2003-05-15 16:30 ` Stephen Leake
2003-05-16 1:08 ` Robert A Duff
2003-05-16 19:24 ` Stephen Leake
2003-05-16 23:47 ` Georg Bauhaus
2003-05-17 0:57 ` Robert A Duff
2003-05-17 1:11 ` Georg Bauhaus
2003-05-17 1:04 ` Robert A Duff
2003-05-16 23:44 ` Georg Bauhaus
2003-05-17 0:23 ` Georg Bauhaus
2003-05-17 1:00 ` Robert A Duff [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox