Re: generic with procedure
From: Stephen Leake (stephen_leake_at_acm.org)
Date: 09/29/04
- Next message: Georg Bauhaus: "Re: Formal and informal type systems?"
- Previous message: Stephen Leake: "Re: Formal and informal type systems?"
- Next in thread: Georg Bauhaus: "Re: generic with procedure"
- Maybe reply: Georg Bauhaus: "Re: generic with procedure"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 28 Sep 2004 19:56:25 -0400 To: comp.lang.ada@ada-france.org
"Rick Santa-Cruz" <rick_santa_cruz75@msn.com> writes:
> Hi,
>
> I am starting to read a bit about generic programming and I am a bit
> confused from it, cause it seems to me a bit different to
> template-programming in C++.
> Sadly I can't figure out the difference between the following:
> 1.) generic
> type Element is private;
> package MyContainers is
> type MyContainer is private;
> procedure Some_Proc(Item : Element);
> end MyContainer;
This is a complete package spec.
> 2.) generic
> type Element is private;
> package MyContainers is
> type MyContainer is private;
> generic
> with procedure Some_Proc(Item : Element);
> end MyContainer;
This is not legal syntax. You could mean:
2a.)
generic
type Element is private;
package MyContainer_2a is
type MyContainer is private;
generic
with procedure Some_Proc(Item : Element);
procedure Foo;
end MyContainer_2a;
or
2b.)
generic
type Element is private;
package MyContainer_2b is
type MyContainer is private;
generic
procedure Some_Proc(Item : Element);
end MyContainer_2b;
In 2a, 'Foo' is a generic procedure, that requires a generic formal
procedure parameter; presumably Foo calls Some_Proc in its body.
In 2b, 'Some_Proc' is a generic procedure, with no generic formal
parameters.
Here are some legal instantiations:
package Container_2a is new My_Container_2a (Integer);
procedure Proc (Item : Element) is
Put_Line ("hello 2a");
end Proc;
procedure Bar is new Container_2a.Foo (Proc);
package Container_2b is new My_Container_2b (Integer);
procedure Proc is new Container_2b.Some_Proc;
-- -- Stephe
- Next message: Georg Bauhaus: "Re: Formal and informal type systems?"
- Previous message: Stephen Leake: "Re: Formal and informal type systems?"
- Next in thread: Georg Bauhaus: "Re: generic with procedure"
- Maybe reply: Georg Bauhaus: "Re: generic with procedure"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]