* Generic units and child units
@ 1999-05-12 0:00 Steve Folly
1999-05-12 0:00 ` Brian Rogoff
1999-05-15 0:00 ` Matthew Heaney
0 siblings, 2 replies; 4+ messages in thread
From: Steve Folly @ 1999-05-12 0:00 UTC (permalink / raw)
Hi,
I'm having a bit of bother combining generic units and child units...
Originally I had a List [of integers] package which dynamically added
integers into a List.Object type
using the standard Node with a Previous and Next pointer, dynamically
allocating each node as required.
Fine so far.
Next, I implemented a List.Iterator child package to enable iteration
through a List.Object
backwards or forwards, starting at the head or tail of the list as required.
Fine again.
Now, what I really wanted was to make List a generic package so it could
store any type rather than
just integers. OK, that works.
The problem I have is how to define the (now) generic List.Iterator package.
The only way I
could get it to compile was to include the keyword 'generic' ie. I now
have...
generic
type Item is private;
package List is
... blah blah
end List;
generic
package List.Iterator is
... blah blah
end List.Iterator;
In my test program I can instantiate a List for integers:
with List;
procedure Test is
package Integer_List is new List (Item => Integer);
begin
... blah blah
end Test;
BUT, how do I get access to List.Iterator for the instantiated integer list.
What is the correct syntax?
Am I even going about this the right way? If possible, I would like to keep
the Iterator child package separate.
I couldn't find anything in the LRM about this.
Thanks to anyone who can help.
--
Regards,
Steve Folly - Y2K compliant since 32nd Februark 1998
http://www.follysplace.demon.co.uk
donationsto:myaccount@mybank.co.uk
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Generic units and child units
1999-05-12 0:00 Generic units and child units Steve Folly
@ 1999-05-12 0:00 ` Brian Rogoff
1999-05-13 0:00 ` Robert A Duff
1999-05-15 0:00 ` Matthew Heaney
1 sibling, 1 reply; 4+ messages in thread
From: Brian Rogoff @ 1999-05-12 0:00 UTC (permalink / raw)
On Wed, 12 May 1999, Steve Folly wrote:
> Hi,
>
> I'm having a bit of bother combining generic units and child units...
>
> Originally I had a List [of integers] package which dynamically added
> integers into a List.Object type
> using the standard Node with a Previous and Next pointer, dynamically
> allocating each node as required.
> Fine so far.
>
> Next, I implemented a List.Iterator child package to enable iteration
> through a List.Object
> backwards or forwards, starting at the head or tail of the list as required.
> Fine again.
>
> Now, what I really wanted was to make List a generic package so it could
> store any type rather than
> just integers. OK, that works.
>
> The problem I have is how to define the (now) generic List.Iterator package.
> The only way I
> could get it to compile was to include the keyword 'generic' ie. I now
> have...
>
> generic
> type Item is private;
> package List is
> ... blah blah
> end List;
>
> generic
> package List.Iterator is
> ... blah blah
> end List.Iterator;
That's right, all children of a generic package must be generic.
>
>
> In my test program I can instantiate a List for integers:
>
> with List;
> procedure Test is
> package Integer_List is new List (Item => Integer);
package Integer_List_Iterator is new Integer_List.Iterator;
is the correct syntax.
> begin
> ... blah blah
> end Test;
>
> BUT, how do I get access to List.Iterator for the instantiated integer list.
> What is the correct syntax?
>
> Am I even going about this the right way? If possible, I would like to keep
> the Iterator child package separate.
I'm still wondering the same thing. In similar libraries, I've used child
packages as you have used them.
-- Brian
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Generic units and child units
1999-05-12 0:00 ` Brian Rogoff
@ 1999-05-13 0:00 ` Robert A Duff
0 siblings, 0 replies; 4+ messages in thread
From: Robert A Duff @ 1999-05-13 0:00 UTC (permalink / raw)
Brian Rogoff <bpr@shell5.ba.best.com> writes:
> > generic
> > type Item is private;
> > package List is
> > ... blah blah
> > end List;
> >
> > generic
> > package List.Iterator is
> > ... blah blah
> > end List.Iterator;
>
> That's right, all children of a generic package must be generic.
> >
> >
> > In my test program I can instantiate a List for integers:
> >
> > with List;
> > procedure Test is
> > package Integer_List is new List (Item => Integer);
>
> package Integer_List_Iterator is new Integer_List.Iterator;
>
> is the correct syntax.
Right, but don't forget to say "with List.Iterator;". When you
instantiate List to create Integer_List, it's as if you were
instantiating the whole hierarchy of children, except that the children
of Integer_List are not visible unless the corresponding children of
List are with'ed. That is, "with List.Iterator;" causes
Integer_List.Iterator to be visible, so you can then instantiate it.
This is all sort of theoretical -- in practise, the compiler will
typically just instantiate the children it needs to; it typically
doesn't even know about the whole hierarchy, because new children can be
added later.
See RM-10.1.1 and 8.3(20).
- Bob
--
Change robert to bob to get my real email address. Sorry.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Generic units and child units
1999-05-12 0:00 Generic units and child units Steve Folly
1999-05-12 0:00 ` Brian Rogoff
@ 1999-05-15 0:00 ` Matthew Heaney
1 sibling, 0 replies; 4+ messages in thread
From: Matthew Heaney @ 1999-05-15 0:00 UTC (permalink / raw)
"Steve Folly" <steve@follysplace.demon.co.uk> writes:
> Am I even going about this the right way? If possible, I would like to keep
> the Iterator child package separate.
Why? The list and its iterator are a highly cohesive pair of types, and
therefore get declared together, in the same package.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~1999-05-15 0:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-05-12 0:00 Generic units and child units Steve Folly
1999-05-12 0:00 ` Brian Rogoff
1999-05-13 0:00 ` Robert A Duff
1999-05-15 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