From: Brian Rogoff <bpr@shell5.ba.best.com>
Subject: Re: [student help] Won't allow package body.
Date: 1998/05/13
Date: 1998-05-13T00:00:00+00:00 [thread overview]
Message-ID: <Pine.BSF.3.96.980513114052.23257A-100000@shell5.ba.best.com> (raw)
In-Reply-To: 6jcfln$ft$1@news.eclipse.net
On Wed, 13 May 1998, MSG wrote:
> Besides the fact that Davic C Hoos, Sr. is correct and that you need to
> provide a more complete example...
>
> Assuming that your spec is compilable but doesn't require a body (a generic
> with no body?...I'll have to think about that later)...you can force need
Bodiless generics are part of a very powerful Ada programming idiom. Using
them we can decouple interfaces (signatures) from implementations. For
example, here is a pseudo-Ada outline of a sequence type, showing roughly
how it might be used.
generic
type Item_Type is private;
type Position_Type is private;
type Sequence_Type is private;
with procedure Initialize (Seq : out Sequence_Type);
with function Is_Empty (Seq : Sequence_Type)
return Boolean is private;
with function Is_Done (Seq : Sequence_Type; Pos : Position_Type)
return Boolean is private;
package Sequence_Sig is
-- Here is your bodiless generic!
end;
generic
type Item_Type is private;
package Lists is
type Position_Type is private;
type List_Type is private;
with procedure Initialize (Seq : out Sequence_Type);
with function Is_Empty (Seq : Sequence_Type)
return Boolean;
with function Is_Done (Seq : Sequence_Type; Pos : Position_Type)
return Boolean;
with function Get_Value_At (Seq : Sequence_Type; Pos : Position_Type)
return Item_Type;
with function Succ (Pos : Position_Type) return Position_Type;
private
-- Singly linked list implementation
end;
package Integer_Lists is new Lists(Item_Type => Integer);
package Integer_Seqs is
new Sequences(Item_Type => Integer_Lists.Item_Type,
Position_Type => Integer_Lists.Position_Type,
Sequence_Type => Integer_Lists.List_Type,
Initialize => Integer_Lists.Initialize
... etc...
);
generic
with Concrete_Seqs is new Sequences(<>);
package Concrete_Algorithms is
...
end Concrete_Algorithms;
A client package like Concrete_Algorithms will only depend on the
Signature and so you can substitute arrays or lists or vectors or
whatever as your sequence.
-- Brian
> for a body by adding a dummy procedure with no code OR you can specify
> "pragma Elaborate_Body;" in the spec of the generic pacakge.
>
> Michael Garnett
>
> Oliver White <ojw@iinet.net.au> wrote in message
> 35514AAC.D46B535C@iinet.net.au...
> I'm compiling a package, the ads file begins as so -
>
>
> generic
>
> type ObjectType is private;
>
> package LinkedListPackage is
> but when I compile, I get this message -
> "generic package LinkedListPackage does not allow a body"
>
> I'm sure there's an obvious error, could you help me?
>
> Oliver White.
>
>
>
>
>
prev parent reply other threads:[~1998-05-13 0:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <35514AAC.D46B535C@iinet.net.au>
1998-05-07 0:00 ` [student help] Won't allow package body David C. Hoos, Sr.
1998-05-13 0:00 ` MSG
1998-05-13 0:00 ` Brian Rogoff [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox