Re: questions to generic

From: Björn Persson (spam-away_at_nowhere.nil)
Date: 09/29/04


Date: Wed, 29 Sep 2004 14:50:11 GMT

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


Relevant Pages

  • Re: Code Management
    ... I put them in a subdirectory and make it a package. ... trick with a .pth file I described above. ... With this setup, tests are organized by subpackage, and each test ... the pythonpath. ...
    (comp.lang.python)
  • Re: package private problem
    ... and move MyClassItem there. ... There is no such thing as a subpackage in Java. ... Package a.b and a.b.c are logically not more related than package a.b and x.y. ...
    (comp.lang.java.help)
  • Re: package private problem
    ... and move MyClassItem there (I need a new subpackage as I will have many ... There is no such thing as a subpackage in Java. ... Package a.b and a.b.c are ...
    (comp.lang.java.help)
  • Structure of packages
    ... I am trying to learn the best way to do intra-package references. ... package looks like this: ... Now I would like to be able to refer to the subpackage b from inside ... It's like when you are running a Python ...
    (comp.lang.python)
  • Re: Ada 95 constructors on limited types
    ... >> package Parent is ... Jeffrey> There's your problem. ... Because they automatically make the package impure for no good reason, ... Declare your access types only if and where you need ...
    (comp.lang.ada)