comp.lang.ada
 help / color / mirror / Atom feed
* Packages and visibility...
@ 1997-03-27  0:00 Marc Bejerano
  1997-03-28  0:00 ` Matthew Heaney
  0 siblings, 1 reply; 2+ messages in thread
From: Marc Bejerano @ 1997-03-27  0:00 UTC (permalink / raw)



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.'

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;

How would I do this? CAN I do this?

TIA, Marc




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

* Re: Packages and visibility...
  1997-03-27  0:00 Packages and visibility Marc Bejerano
@ 1997-03-28  0:00 ` Matthew Heaney
  0 siblings, 0 replies; 2+ messages in thread
From: Matthew Heaney @ 1997-03-28  0:00 UTC (permalink / raw)



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
<mailto:matthew_heaney@acm.org>
(818) 985-1271




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

end of thread, other threads:[~1997-03-28  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-03-27  0:00 Packages and visibility Marc Bejerano
1997-03-28  0:00 ` Matthew Heaney

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