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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,4d972ac0c79198a5 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-05-16 18:00:01 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!newsswitch.lcs.mit.edu!newsfeed.mathworks.com.MISMATCH!newsfeed!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Generic child units Date: 16 May 2003 21:00:00 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <3ec12f93$1@epflnews.epfl.ch> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1053133200 21305 199.172.62.241 (17 May 2003 01:00:00 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Sat, 17 May 2003 01:00:00 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: archiver1.google.com comp.lang.ada:37423 Date: 2003-05-16T21:00:00-04:00 List-Id: Georg Bauhaus writes: > Stephen Leake wrote: > : Rodrigo Garc?a 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