comp.lang.ada
 help / color / mirror / Atom feed
* (generic) child package of generic package; intantiation of
@ 2001-01-29 16:30 Peter Hend�n
  2001-01-29 17:20 ` Marc A. Criley
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Peter Hend�n @ 2001-01-29 16:30 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 452 bytes --]

I have the following:

generic
    Count : in Natural := 1;
package Parent is
    ...
end Parent;

generic
package Parent.RarelyUsedOps is
    ...
end Parent.RarelyUsedOps;

I have no problem instantiating Parent, of course, but how in the name of Ms
Lovelace do I instantiate the child package?

TIA and Regards,
Peter

--
Peter Hend�n           http://www.algonet.se/~phenden
ICQ: 14672398
Teknisk Dokumentation AB          http://www.tdab.com





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

* Re: (generic) child package of generic package; intantiation of
  2001-01-29 16:30 Peter Hend�n
@ 2001-01-29 17:20 ` Marc A. Criley
  2001-01-29 17:24 ` mark.biggar
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Marc A. Criley @ 2001-01-29 17:20 UTC (permalink / raw)


"Peter Hend�n" wrote:
> 
> I have the following:
> 
> generic
>     Count : in Natural := 1;
> package Parent is
>     ...
> end Parent;
> 
> generic
> package Parent.RarelyUsedOps is
>     ...
> end Parent.RarelyUsedOps;
> 
> I have no problem instantiating Parent, of course, but how in the name of Ms
> Lovelace do I instantiate the child package?
> 
> TIA and Regards,
> Peter

   package Mom is new Parent;

   package Restful_Sleep is new Mom.RarelyUsedOps;


Marc A. Criley
Senior Staff Engineer
Quadrus Corporation
www.quadruscorp.com



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

* Re: (generic) child package of generic package; intantiation of
  2001-01-29 16:30 Peter Hend�n
  2001-01-29 17:20 ` Marc A. Criley
@ 2001-01-29 17:24 ` mark.biggar
  2001-01-29 17:25 ` Pat Rogers
  2001-01-30  4:48 ` Jeffrey Carter
  3 siblings, 0 replies; 10+ messages in thread
From: mark.biggar @ 2001-01-29 17:24 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1405 bytes --]

In article <LUgd6.9728$Qb7.1473404@newsb.telia.net>,
  "Peter Hend�n" <phenden@tdab.com> wrote:
> I have the following:
>
> generic
>     Count : in Natural := 1;
> package Parent is
>     ...
> end Parent;
>
> generic
> package Parent.RarelyUsedOps is
>     ...
> end Parent.RarelyUsedOps;
>
> I have no problem instantiating Parent, of course, but how in the name
of Ms
> Lovelace do I instantiate the child package?

with Parent;
package p is new Parent;

with P.RarelyUsedOps;
package P.R is new P.RarelyUsedOps;

When you instantiate a generic package that has generic children
the newly created package automaticaly gets partialy instantiated
generic children that correspond to the generic children of the
original generic package.  In a lot of way the children of a package
work as if they were directly imbeded in the parent package.  If
you example instead was:

generic
     Count : in Natural := 1;
package Parent is
     ...

generic
package Parent.RarelyUsedOps is
    ...
end Parent.RarelyUsedOps;

     ...

end Parent;

Then you could used a similar set of instantiations:

with Parent;
package P is new Parent;

with P;
package R is new P.RarelyUsedOps;

Note that in both cases you instantiate a child/sub-package of the
newly instantiated package not of the original generic parent package.

--
Mark Biggar
mark.biggar@trustedsyslabsl.com



Sent via Deja.com
http://www.deja.com/



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

* Re: (generic) child package of generic package; intantiation of
  2001-01-29 16:30 Peter Hend�n
  2001-01-29 17:20 ` Marc A. Criley
  2001-01-29 17:24 ` mark.biggar
@ 2001-01-29 17:25 ` Pat Rogers
  2001-01-29 20:46   ` Peter Hend�n
  2001-01-30  4:48 ` Jeffrey Carter
  3 siblings, 1 reply; 10+ messages in thread
From: Pat Rogers @ 2001-01-29 17:25 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1105 bytes --]

"Peter Hend�n" <phenden@tdab.com> wrote in message
news:LUgd6.9728$Qb7.1473404@newsb.telia.net...
> I have the following:
>
> generic
>     Count : in Natural := 1;
> package Parent is
>     ...
> end Parent;
>
> generic
> package Parent.RarelyUsedOps is
>     ...
> end Parent.RarelyUsedOps;
>
> I have no problem instantiating Parent, of course, but how in the name of
Ms
> Lovelace do I instantiate the child package?

Imagine the declaration of the child generic is nested within an
*instantiation* of the parent unit, and use the instance name accordingly.
For example, if an instance of the Parent is Foo, as in:

    package Foo is new Parent;

we could say:

    package Bar is new Foo.RarelyUsedOps;

If you keep the visibility issues in mind (i.e. the child's view of the
parent's declarations) this approach will make more sense.

---
Patrick Rogers                       Consulting and Training in:
http://www.classwide.com        Real-Time/OO Languages
progers@classwide.com          Hard Deadline Schedulability Analysis
(281)648-3165                          Software Fault Tolerance





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

* Re: (generic) child package of generic package; intantiation of
  2001-01-29 17:25 ` Pat Rogers
@ 2001-01-29 20:46   ` Peter Hend�n
  2001-01-30 16:56     ` Tucker Taft
  0 siblings, 1 reply; 10+ messages in thread
From: Peter Hend�n @ 2001-01-29 20:46 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 280 bytes --]

Mark, Marc, Pat:

Thanks a lot. I should have known this, but got a bit confused over other
errors I got when I first compiled.

Thanks again
Peter

--
Peter Hend�n           http://www.algonet.se/~phenden
ICQ: 14672398
Teknisk Dokumentation AB          http://www.tdab.com





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

* Re: (generic) child package of generic package; intantiation of
  2001-01-29 16:30 Peter Hend�n
                   ` (2 preceding siblings ...)
  2001-01-29 17:25 ` Pat Rogers
@ 2001-01-30  4:48 ` Jeffrey Carter
  2001-01-30 11:53   ` Peter Hend�n
  3 siblings, 1 reply; 10+ messages in thread
From: Jeffrey Carter @ 2001-01-30  4:48 UTC (permalink / raw)


"Peter Hend�n" wrote:
> I have no problem instantiating Parent, of course, but how in the name of Ms
> Lovelace do I instantiate the child package?

Why do you invoke the star of "Deep Throat" when trying to understand
Ada? Ada was Mrs. King, Countess Lovelace, but not Miss/Mrs./Ms.
Lovelace.

-- 
Jeff Carter
"You empty-headed animal-food-trough wiper."
Monty Python & the Holy Grail



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

* Re: (generic) child package of generic package; intantiation of
  2001-01-30  4:48 ` Jeffrey Carter
@ 2001-01-30 11:53   ` Peter Hend�n
  0 siblings, 0 replies; 10+ messages in thread
From: Peter Hend�n @ 2001-01-30 11:53 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 462 bytes --]

"Jeffrey Carter" wrote:
> Why do you invoke the star of "Deep Throat" when trying to understand
> Ada? Ada was Mrs. King, Countess Lovelace, but not Miss/Mrs./Ms.
> Lovelace.

Maybe so as not to speak our Ladys name in vain? Oh well. In any case I
apologise profusely to any and all who may have taken exception.

Regards,
Peter

--
Peter Hend�n           http://www.algonet.se/~phenden
ICQ: 14672398
Teknisk Dokumentation AB          http://www.tdab.com






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

* Re: (generic) child package of generic package; intantiation of
  2001-01-29 20:46   ` Peter Hend�n
@ 2001-01-30 16:56     ` Tucker Taft
  2001-01-30 21:33       ` Peter Hend�n
  0 siblings, 1 reply; 10+ messages in thread
From: Tucker Taft @ 2001-01-30 16:56 UTC (permalink / raw)


"Peter Hend�n" wrote:
> 
> Mark, Marc, Pat:
> 
> Thanks a lot. I should have known this, but got a bit confused over other
> errors I got when I first compiled.

Unfortunately, Mark, Marc, and Pat all forgot to mention that you
have to "with" the child unit where you plan to instantiate it.
The way to think about a "with" clause for a child is that it effectively
inserts the child into the parent.  With a child of a generic,
inserting the child into the generic parent means that all instances
of the generic parent now include the generic child nested within
them.  You can then instantiate one of those nested generics,
given any instance of the parent.

But the key thing to remember is that the nested generic is only
made visible where a "with" clause for the generic child applies.

> 
> Thanks again
> Peter
> 
> --
> Peter Hend�n           http://www.algonet.se/~phenden
> ICQ: 14672398
> Teknisk Dokumentation AB          http://www.tdab.com

-- 
-Tucker Taft   stt@avercom.net   http://www.averstar.com/~stt/
Chief Technology Officer, AverCom, Inc. (A Titan Company) Burlington, MA  USA
(AverCom was formed 1/1/01 from the Commercial Division of AverStar)
(http://www.averstar.com/services/ebusiness_applications.html)



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

* Re: (generic) child package of generic package; intantiation of
  2001-01-30 16:56     ` Tucker Taft
@ 2001-01-30 21:33       ` Peter Hend�n
  0 siblings, 0 replies; 10+ messages in thread
From: Peter Hend�n @ 2001-01-30 21:33 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1456 bytes --]

"Tucker Taft" wrote:
> Unfortunately, Mark, Marc, and Pat all forgot to mention that you
> have to "with" the child unit where you plan to instantiate it.
> The way to think about a "with" clause for a child is that it effectively
> inserts the child into the parent.  With a child of a generic,
> inserting the child into the generic parent means that all instances
> of the generic parent now include the generic child nested within
> them.  You can then instantiate one of those nested generics,
> given any instance of the parent.
What I wound up with was (using gnat 3.13p):
--- GenParent.ads
generic
   ...
package GenParent is
   ...
end GenParent;

--- GenParent-GenChild.ads
generic
package GenParent.GenChild is
   ...
end GenParent.GenChild;

--- InstantiatedParent.ads
with GenParent;

package InstantiatedParent is new GenParent(...);

--- InstantiatedParent - InstantiatedChild.ads
with GenParent.GenChild;         -- have to with the generic child package
(1)

package InstantiatedParent.InstantiatedChild is new
InstantiatedParent.GenChild;
----

(1) Is this what you meant?

Is the above the way to do it? Any better ways?

> But the key thing to remember is that the nested generic is only
> made visible where a "with" clause for the generic child applies.

Grateful for any and all help.

Regards,
Peter

--
Peter Hend�n           http://www.algonet.se/~phenden
ICQ: 14672398
Teknisk Dokumentation AB          http://www.tdab.com





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

* Re: (generic) child package of generic package; intantiation of
@ 2001-01-31  5:34 Christoph Grein
  0 siblings, 0 replies; 10+ messages in thread
From: Christoph Grein @ 2001-01-31  5:34 UTC (permalink / raw)
  To: comp.lang.ada

Peter Hendén wrote:

> with GenParent.GenChild;  -- have to with the generic child package (1)
>
> package InstantiatedParent.InstantiatedChild is new
>         InstantiatedParent.GenChild;

That's correct. But you need not instantiate as a child, you can instantiate in 
any hierarchy:

   with GenParent.GenChild;
   with InstantiatedParent;  -- you need then also this

   package Instantiated_Anywhere is new InstantiatedParent.GenChild;





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

end of thread, other threads:[~2001-01-31  5:34 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-01-31  5:34 (generic) child package of generic package; intantiation of Christoph Grein
  -- strict thread matches above, loose matches on Subject: below --
2001-01-29 16:30 Peter Hend�n
2001-01-29 17:20 ` Marc A. Criley
2001-01-29 17:24 ` mark.biggar
2001-01-29 17:25 ` Pat Rogers
2001-01-29 20:46   ` Peter Hend�n
2001-01-30 16:56     ` Tucker Taft
2001-01-30 21:33       ` Peter Hend�n
2001-01-30  4:48 ` Jeffrey Carter
2001-01-30 11:53   ` Peter Hend�n

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