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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,f13a30389971bb4e X-Google-Attributes: gid103376,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: Packages and visibility... Date: 1997/03/28 Message-ID: #1/1 X-Deja-AN: 228953903 References: <333AB81E.109B@linkabit.titan.com> Organization: Estormza Software Newsgroups: comp.lang.ada Date: 1997-03-28T00:00:00+00:00 List-Id: In article <333AB81E.109B@linkabit.titan.com>, t_mjb@linkabit.titan.com wrote: >I have a package 'foo' with a data type 'bar' and various functions and >procedures that act upon 'bar' that I would like to place in a child >package also named 'bar.' I'm not sure what you want to do. Do you want a child package of Foo named Bar, as follows: package Foo.Bar is type T is ...; end Foo.Bar; or, do you want a nested package: package Foo is package Bar is type T is ...; end Bar; end Foo; >In the program I would like to access this as: > >with foo; use foo; >procedure test is > b: bar; >begin > bar.init(b); >end test; You must understand one Very Important Thing about programming in Ada: A type is not a module. Yes, many current languages equate the two concepts, but in Ada, the type and module are orthogonal language features. In Ada, you should not name your package and type the same. If you really want the syntax suggested by your example, then don't program in Ada. A type declaration and its primitive operations are declared in a package specifically dedicated to that purpose. Name the package the plural of the type. I also like to qualify the type name with an adjective. For example: generic type Stack_Item is private; package Stacks_G is type Root_Stack is abstract tagged private; procedure Push (Item : in Stack_Item; On : in out Root_Stack) is abstract; function Top (Stack : Root_Stack) return Stack_Item is abstract; ... end Stacks_G; A child package containing a derivation might look like: package Stacks_G.Bounded_G is type Bounded_Stack is new Root_Stack with private; ... end Stacks_G.Bounded_G; The instantiations are as follows: with Stacks_G; package Integer_Stacks is new Stacks_G (Integer); with Stacks_G.Bounded_G; package Integer_Stacks.Bounded is new Integer_Stacks.Bounded_G; Then use it as follows: with Integer_Stacks.Bounded; procedure Proc is The_Stack : Integer_Stacks.Bounded.Bounded_Stack; use Integer_Stacks.Bounded; begin Push (5, On => The_Stack); end; Quelle langue! Matt -------------------------------------------------------------------- Matthew Heaney Software Development Consultant (818) 985-1271