* packet type ?
@ 2000-01-14 0:00 Alfred Hilscher
2000-01-14 0:00 ` Ted Dennison
0 siblings, 1 reply; 10+ messages in thread
From: Alfred Hilscher @ 2000-01-14 0:00 UTC (permalink / raw)
Hi all,
I am not so familiar with the OO-extensions of Ada95 so maybe my
question is obsolete. What I'm looking for is something like a "packege
type" (similar to "task type"). What I want do is something like this:
package type stack is
push (item : in ...);
pop (item : out ...)
end stack
procedure application is
User_stack : stack;
Supervisor_stack : stack;
Interrupt_stack : stack;
begin
...
end application;
Any suggestions how to do this ?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: packet type ?
2000-01-14 0:00 packet type ? Alfred Hilscher
@ 2000-01-14 0:00 ` Ted Dennison
2000-01-18 0:00 ` Alfred Hilscher
0 siblings, 1 reply; 10+ messages in thread
From: Ted Dennison @ 2000-01-14 0:00 UTC (permalink / raw)
In article <387F3DD1.485F7C70@icn.siemens.de>,
Alfred Hilscher <Alfred.Hilscher@icn.siemens.de> wrote:
> Hi all,
>
> I am not so familiar with the OO-extensions of Ada95 so maybe my
> question is obsolete. What I'm looking for is something like a
"packege
> type" (similar to "task type"). What I want do is something like this:
> Any suggestions how to do this ?
That's what generics with package formal parameters are for.
--
T.E.D.
http://www.telepath.com/~dennison/Ted/TED.html
Sent via Deja.com http://www.deja.com/
Before you buy.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: packet type ?
2000-01-14 0:00 ` Ted Dennison
@ 2000-01-18 0:00 ` Alfred Hilscher
2000-01-18 0:00 ` Brian Rogoff
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Alfred Hilscher @ 2000-01-18 0:00 UTC (permalink / raw)
Ted Dennison wrote:
>
> > question is obsolete. What I'm looking for is something like a
> "packege
> > type" (similar to "task type"). What I want do is something like this:
>
> > Any suggestions how to do this ?
>
> That's what generics with package formal parameters are for.
I think thats not quite the same. Taking the example below, how would
you do this with generics ?
package type stack is
push (item : in ...);
pop (item : out ...)
end stack
procedure application is
User_stack : stack;
Supervisor_stack : stack;
Interrupt_stack : stack;
Any_Stack : access Stack;
begin
...
Any_Stack := new Stack; -- how do this ???
...
end application;
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: packet type ?
2000-01-18 0:00 ` Alfred Hilscher
@ 2000-01-18 0:00 ` Brian Rogoff
2000-01-18 0:00 ` Ted Dennison
2000-01-19 0:00 ` Anders Gidenstam
2 siblings, 0 replies; 10+ messages in thread
From: Brian Rogoff @ 2000-01-18 0:00 UTC (permalink / raw)
On Tue, 18 Jan 2000, Alfred Hilscher wrote:
> Ted Dennison wrote:
> >
> > > question is obsolete. What I'm looking for is something like a
> > "packege
> > > type" (similar to "task type"). What I want do is something like this:
> >
> > > Any suggestions how to do this ?
> >
> > That's what generics with package formal parameters are for.
>
>
> I think thats not quite the same. Taking the example below, how would
> you do this with generics ?
>
>
> package type stack is
> push (item : in ...);
> pop (item : out ...)
> end stack
>
> procedure application is
> User_stack : stack;
> Supervisor_stack : stack;
> Interrupt_stack : stack;
>
> Any_Stack : access Stack;
> begin
> ...
> Any_Stack := new Stack; -- how do this ???
> ...
> end application;
Packages are not first class entities in Ada. They cannot be assigned to
variables or passed as function arguments. The closest you get is as
T.E.D. suggested, by using generic formal package parameters which give
you a small language for combining the packages.
What is there that you wished to do with first class packages that you
couldn't do equally nicely with plain old ADTs, maybe even using tagged
types to be fancy :-). The stack example is easily programmed that way.
-- Brian
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: packet type ?
2000-01-18 0:00 ` Alfred Hilscher
2000-01-18 0:00 ` Brian Rogoff
@ 2000-01-18 0:00 ` Ted Dennison
2000-01-19 0:00 ` Anders Gidenstam
2 siblings, 0 replies; 10+ messages in thread
From: Ted Dennison @ 2000-01-18 0:00 UTC (permalink / raw)
In article <38845EBD.6F90845D@icn.siemens.de>,
Alfred Hilscher <Alfred.Hilscher@icn.siemens.de> wrote:
>
> Ted Dennison wrote:
> I think thats not quite the same. Taking the example below, how would
> you do this with generics ?
>
> package type stack is
> push (item : in ...);
> pop (item : out ...)
> end stack
>
> procedure application is
> User_stack : stack;
> Supervisor_stack : stack;
> Interrupt_stack : stack;
>
> Any_Stack : access Stack;
> begin
> ...
> Any_Stack := new Stack; -- how do this ???
> ...
> end application;
The flip answer is I'd download the Booch components. :-)
Code wise, I'd do something like this:
generic
type Element is private;
package Stack is
type Instance is private;
Push (Item : in Element
Onto : in out Instance);
Pop (Item : out Element;
Off_Of : in out Instance);
private
...
end Stack;
It looks like your confusion is based on experience w/ other OO-based
languages. In Ada types and packages are completely separate kinds of
entities. Packages exist to provide for organizing other things into a
single namespace. Types define the data structure of objects.
Subprograms are defined within the context of packages, not types or
objects. For instance, to call what I created above, first I'd
instantiate it with my element type thusly:
with Stack;
...
procedure Whatever is
package Integer_Stack is new Stack (Integer);
Then I call push this way:
Pushee : Integer := 20;
Old_Integers : Integer_Stack.Instance;
...
begin
Integer_Stack.Push (Item => Pushee,
Onto => Old_Integers);
--
T.E.D.
http://www.telepath.com/~dennison/Ted/TED.html
Sent via Deja.com http://www.deja.com/
Before you buy.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: packet type ?
2000-01-19 0:00 ` Anders Gidenstam
@ 2000-01-19 0:00 ` Brian Rogoff
2000-01-20 0:00 ` Andy S
0 siblings, 1 reply; 10+ messages in thread
From: Brian Rogoff @ 2000-01-19 0:00 UTC (permalink / raw)
On 19 Jan 2000, Anders Gidenstam wrote:
> Well, you make a generic package containing the stack ADT.
> It'll be something like this:
>
> generic
> type Element_Type is private;
> package Stack_ADT is
>
> type Stack(Size : Natural) is private;
>
> procedure Push (S : in out Stack; I : in Element_Type);
> procedure Pop (S : in out Stack; I : out Element_Type);
>
> ...
>
> private
> type Element_Array is array (Positive range <>) of Element_Type;
>
> type Stack(Size : Natural) is
> record
> S : Element_Array (1..Size);
> Top : Natural := 0;
> end record;
> end Stack_ADT;
>
> And you use it like this:
>
> with Stack_ADT;
> procedure Something is
>
> package Integer_Stack is new Stack_ADT (Integer);
> use Integer_Stack;
> package Float_Stack is new Stack_ADT (Float);
> use Float_Stack;
>
>
> My_Stack : Integer_Stack.Stack (Size => 100);
> Some_Stack : Float_Stack.Stack (Size => 50);
> begin
> Push (My_Stack, 3);
> Push (Some_Stack, 7.0);
> ...
>
> I hope this was helpful in understanding this part of Ada.
> (Note that this isn't OO in the C++ sense, you can't let any type inherit
> the stack's properties but I don't think that type of inheritance is needed
> for an ADT like this. And of course one could make the stack a tagged type
> which would allow inheritance.)
Ada 95 also allows you to create a stack signature
generic
type Item_Type is private;
type Stack_Type is private;
with procedure Push(Stack : in out Stack_Type; Item : in Item_Type);
with procedure Pop(Stack : in out Stack_Type; Item : out Item_Type);
...
package Stack_Sig is begin end;
and write code which only depends on an instantiation having that profile,
so that your stack code and many others can supply the stack ADT for the
code. This is a very nice feature of Ada 95 which is not described in many
Ada books; Barnes and Ben-Ari are exceptional here.
-- Brian
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: packet type ?
2000-01-18 0:00 ` Alfred Hilscher
2000-01-18 0:00 ` Brian Rogoff
2000-01-18 0:00 ` Ted Dennison
@ 2000-01-19 0:00 ` Anders Gidenstam
2000-01-19 0:00 ` Brian Rogoff
2 siblings, 1 reply; 10+ messages in thread
From: Anders Gidenstam @ 2000-01-19 0:00 UTC (permalink / raw)
In article <38845EBD.6F90845D@icn.siemens.de>,
Alfred Hilscher <Alfred.Hilscher@icn.siemens.de> writes:
>
> Ted Dennison wrote:
>>
>> > question is obsolete. What I'm looking for is something like a
>> "packege
>> > type" (similar to "task type"). What I want do is something like this:
>>
>> > Any suggestions how to do this ?
>>
>> That's what generics with package formal parameters are for.
>
>
> I think thats not quite the same. Taking the example below, how would
> you do this with generics ?
>
>
> package type stack is
> push (item : in ...);
> pop (item : out ...)
> end stack
>
> procedure application is
> User_stack : stack;
> Supervisor_stack : stack;
> Interrupt_stack : stack;
>
> Any_Stack : access Stack;
> begin
> ...
> Any_Stack := new Stack; -- how do this ???
> ...
> end application;
Well, you make a generic package containing the stack ADT.
It'll be something like this:
generic
type Element_Type is private;
package Stack_ADT is
type Stack(Size : Natural) is private;
procedure Push (S : in out Stack; I : in Element_Type);
procedure Pop (S : in out Stack; I : out Element_Type);
...
private
type Element_Array is array (Positive range <>) of Element_Type;
type Stack(Size : Natural) is
record
S : Element_Array (1..Size);
Top : Natural := 0;
end record;
end Stack_ADT;
And you use it like this:
with Stack_ADT;
procedure Something is
package Integer_Stack is new Stack_ADT (Integer);
use Integer_Stack;
package Float_Stack is new Stack_ADT (Float);
use Float_Stack;
My_Stack : Integer_Stack.Stack (Size => 100);
Some_Stack : Float_Stack.Stack (Size => 50);
begin
Push (My_Stack, 3);
Push (Some_Stack, 7.0);
...
I hope this was helpful in understanding this part of Ada.
(Note that this isn't OO in the C++ sense, you can't let any type inherit
the stack's properties but I don't think that type of inheritance is needed
for an ADT like this. And of course one could make the stack a tagged type
which would allow inheritance.)
/Anders
--
"A well-written program is its own heaven;
a poorly-written program is its own hell."
- The Tao of Programming
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: packet type ?
2000-01-20 0:00 ` Andy S
@ 2000-01-20 0:00 ` Brian Rogoff
2000-01-20 0:00 ` Tucker Taft
1 sibling, 0 replies; 10+ messages in thread
From: Brian Rogoff @ 2000-01-20 0:00 UTC (permalink / raw)
Quite sure, but you have to fix my syntax error. :-)
-- Brian
On Thu, 20 Jan 2000, Andy S wrote:
> Brian Rogoff wrote:
> > Ada 95 also allows you to create a stack signature
> >
> > generic
> > type Item_Type is private;
> > type Stack_Type is private;
> > with procedure Push(Stack : in out Stack_Type; Item : in Item_Type);
> > with procedure Pop(Stack : in out Stack_Type; Item : out Item_Type);
> > ...
> > package Stack_Sig is begin end;
> >
> > and write code which only depends on an instantiation having that profile,
> > so that your stack code and many others can supply the stack ADT for the
> > code. This is a very nice feature of Ada 95 which is not described in many
> > Ada books; Barnes and Ben-Ari are exceptional here.
> >
> Are you sure? My GNAT compiler barffed at this one !
>
> ___________________________________________
>
> Andy Starritt
> ___________________________________________
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: packet type ?
2000-01-19 0:00 ` Brian Rogoff
@ 2000-01-20 0:00 ` Andy S
2000-01-20 0:00 ` Brian Rogoff
2000-01-20 0:00 ` Tucker Taft
0 siblings, 2 replies; 10+ messages in thread
From: Andy S @ 2000-01-20 0:00 UTC (permalink / raw)
Brian Rogoff wrote:
> Ada 95 also allows you to create a stack signature
>
> generic
> type Item_Type is private;
> type Stack_Type is private;
> with procedure Push(Stack : in out Stack_Type; Item : in Item_Type);
> with procedure Pop(Stack : in out Stack_Type; Item : out Item_Type);
> ...
> package Stack_Sig is begin end;
>
> and write code which only depends on an instantiation having that profile,
> so that your stack code and many others can supply the stack ADT for the
> code. This is a very nice feature of Ada 95 which is not described in many
> Ada books; Barnes and Ben-Ari are exceptional here.
>
Are you sure? My GNAT compiler barffed at this one !
___________________________________________
Andy Starritt
___________________________________________
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: packet type ?
2000-01-20 0:00 ` Andy S
2000-01-20 0:00 ` Brian Rogoff
@ 2000-01-20 0:00 ` Tucker Taft
1 sibling, 0 replies; 10+ messages in thread
From: Tucker Taft @ 2000-01-20 0:00 UTC (permalink / raw)
Andy S wrote:
>
> Brian Rogoff wrote:
> > Ada 95 also allows you to create a stack signature
> >
> > generic
> > type Item_Type is private;
> > type Stack_Type is private;
> > with procedure Push(Stack : in out Stack_Type; Item : in Item_Type);
> > with procedure Pop(Stack : in out Stack_Type; Item : out Item_Type);
> > ...
> > package Stack_Sig is begin end;
> >
> > and write code which only depends on an instantiation having that profile,
> > so that your stack code and many others can supply the stack ADT for the
> > code. This is a very nice feature of Ada 95 which is not described in many
> > Ada books; Barnes and Ben-Ari are exceptional here.
> >
> Are you sure? My GNAT compiler barffed at this one !
Try removing the "..." and the "begin" from the above.
> __________________________________________
>
> Andy Starritt
> ___________________________________________
--
-Tucker Taft stt@averstar.com http://www.averstar.com/~stt/
Technical Director, Distributed IT Solutions (www.averstar.com/tools)
AverStar (formerly Intermetrics, Inc.) Burlington, MA USA
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2000-01-20 0:00 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-01-14 0:00 packet type ? Alfred Hilscher
2000-01-14 0:00 ` Ted Dennison
2000-01-18 0:00 ` Alfred Hilscher
2000-01-18 0:00 ` Brian Rogoff
2000-01-18 0:00 ` Ted Dennison
2000-01-19 0:00 ` Anders Gidenstam
2000-01-19 0:00 ` Brian Rogoff
2000-01-20 0:00 ` Andy S
2000-01-20 0:00 ` Brian Rogoff
2000-01-20 0:00 ` Tucker Taft
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox