* questions to generic
@ 2004-09-28 23:58 Rick Santa-Cruz
2004-09-29 2:17 ` Georg Bauhaus
0 siblings, 1 reply; 7+ messages in thread
From: Rick Santa-Cruz @ 2004-09-28 23:58 UTC (permalink / raw)
Hi,
I have 2 questions:
1. ) Is it possible to create a generic procedure, which is not part of a
package, something like:
procedure Gen_Test_Client is
generic
type Element is private;
procedure Gen_Proc(Element: Element);
...
where Gen_Test_Client is the start-procedure?
2.) How is it possible to create a generic child package?
Thanks in advance,
Rick
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: questions to generic
2004-09-28 23:58 questions to generic Rick Santa-Cruz
@ 2004-09-29 2:17 ` Georg Bauhaus
2004-09-29 9:58 ` Rick Santa-Cruz
0 siblings, 1 reply; 7+ messages in thread
From: Georg Bauhaus @ 2004-09-29 2:17 UTC (permalink / raw)
Rick Santa-Cruz <rick_santa_cruz75@msn.com> wrote:
: Hi,
:
: I have 2 questions:
: 1. ) Is it possible to create a generic procedure, which is not part of a
: package,
yes, the way you have done.
: where Gen_Test_Client is the start-procedure?
no. It has to be instantiated somewhere to become a real procedure.
: 2.) How is it possible to create a generic child package?
You might find it useful to think of child packages as nested
packages. Consider the steps it takes to make an instance
of the outer package. After you have an instance of the outer
package, you are back at step 1, where you instantiate some generic
package :-)
-- Georg
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: questions to generic
2004-09-29 2:17 ` Georg Bauhaus
@ 2004-09-29 9:58 ` Rick Santa-Cruz
2004-09-29 11:33 ` Georg Bauhaus
2004-09-29 14:50 ` Björn Persson
0 siblings, 2 replies; 7+ messages in thread
From: Rick Santa-Cruz @ 2004-09-29 9:58 UTC (permalink / raw)
Hi,
> yes, the way you have done.
>
> : where Gen_Test_Client is the start-procedure?
>
> no. It has to be instantiated somewhere to become a real procedure.
And how and where do I have to instantiate the procedure then?
>
> : 2.) How is it possible to create a generic child package?
>
> You might find it useful to think of child packages as nested
> packages. Consider the steps it takes to make an instance
> of the outer package. After you have an instance of the outer
> package, you are back at step 1, where you instantiate some generic
> package :-)
So is it this way correct:
package Pack1 is
generic
type Element is private;
package Child_Pack is
procedure Proc(El: Element);
end Child_Pack;
end Pack1;
--body
package body Pack1 is
package bodY Child_Pack is
procedure Proc(El: Element) is
El1: Element;
begin
El1:= El;
end Proc;
end Child_Pack;
end Pack1;
-- test-client:
with Pack1; -- by the way when I write here: with Pack1.Child_Pack; I get a
compilation-error. Why?
procedure Gen_Test_Client is
package S_2 is new Pack1.Child_Pack(Integer);
....
Thanks,
Rick
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: questions to generic
2004-09-29 9:58 ` Rick Santa-Cruz
@ 2004-09-29 11:33 ` Georg Bauhaus
2004-09-29 14:52 ` Björn Persson
2004-09-29 14:50 ` Björn Persson
1 sibling, 1 reply; 7+ messages in thread
From: Georg Bauhaus @ 2004-09-29 11:33 UTC (permalink / raw)
Rick Santa-Cruz <rick_santa_cruz75@msn.com> wrote:
: Hi,
:
:> yes, the way you have done.
:>
:> : where Gen_Test_Client is the start-procedure?
:>
:> no. It has to be instantiated somewhere to become a real procedure.
: And how and where do I have to instantiate the procedure then?
wherever you like :)
: So is it this way correct:
Does you compiler report anything?
: -- test-client:
: with Pack1; -- by the way when I write here: with Pack1.Child_Pack; I get a
: compilation-error. Why?
That's the point. Pack1 is generic, it is not an instance.
By writing Some_Package.Something_Else, you are referring
to Something_Else in a real package (which can be a plain
package, or an real instance of a generic package).
Imagine you had a generic package as before,
with a nested generic. But the formal parameter of the
nested generic is different from the formal parameter of
the outer package.
The outer is instantiated with some actual type. What have
you got?
-- Georg
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: questions to generic
2004-09-29 9:58 ` Rick Santa-Cruz
2004-09-29 11:33 ` Georg Bauhaus
@ 2004-09-29 14:50 ` Björn Persson
1 sibling, 0 replies; 7+ messages in thread
From: Björn Persson @ 2004-09-29 14:50 UTC (permalink / raw)
Rick Santa-Cruz wrote:
> And how and where do I have to instantiate the procedure then?
For example:
procedure Gen_Test_Client is
generic
type Element is private;
procedure Gen_Proc(El: Element);
procedure Gen_Proc(El: Element) is
begin
null;
end Gen_Proc;
procedure Natural_Proc is new Gen_Proc(Natural);
procedure Character_Proc is new Gen_Proc(Character);
begin -- Gen_Test_Client
Natural_Proc(5);
Character_Proc('X');
end Gen_Test_Client;
> So is it this way correct:
> package Pack1 is
> generic
> type Element is private;
> package Child_Pack is
> procedure Proc(El: Element);
> end Child_Pack;
> end Pack1;
Strictly speaking, that's a subpackage. A child package is specified
separately. (With Gnat it will be in its own file.)
package Parent is
package Subpackage is
end Subpackage;
end Parent;
package Parent.Child_Package is
end Parent.Child_Package;
> with Pack1; -- by the way when I write here: with Pack1.Child_Pack; I get a
> compilation-error. Why?
When you write "with Pack1;" you get access to everything in Pack1,
including subpackages. For a child package you'd have to write "with
Parent.Child_Package;".
--
Björn Persson PGP key A88682FD
omb jor ers @sv ge.
r o.b n.p son eri nu
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2004-09-29 17:11 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-28 23:58 questions to generic Rick Santa-Cruz
2004-09-29 2:17 ` Georg Bauhaus
2004-09-29 9:58 ` Rick Santa-Cruz
2004-09-29 11:33 ` Georg Bauhaus
2004-09-29 14:52 ` Björn Persson
2004-09-29 17:11 ` Georg Bauhaus
2004-09-29 14:50 ` Björn Persson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox