From: Adam Beneschan <adam@irvine.com>
Subject: Re: Declaring private packages to instantiate generics?
Date: Wed, 16 May 2012 20:37:02 -0700 (PDT)
Date: 2012-05-16T20:37:02-07:00 [thread overview]
Message-ID: <7294223.88.1337225822800.JavaMail.geo-discussion-forums@vbli11> (raw)
In-Reply-To: <25586653.906.1337178987063.JavaMail.geo-discussion-forums@pbcvy1>
On Wednesday, May 16, 2012 7:36:27 AM UTC-7, Adam Beneschan wrote:
> > package FOO is
> > procedure P;
> > end FOO;
> >
> > package body FOO is
> > package BAR is new SOME_GENERIC_PACKAGE;
> > procedure P is new BAR.P;
> > end FOO;
> > --->%---
> >
> > Can I somehow provide the body of P without writing a procedure which just
> > forwards to an instantiation of BAR.P, IOW without having to write:
> >
> > ---%<---
> > package body FOO is
> > package BAR is new SOME_GENERIC_PACKAGE;
> > procedure BAR_P is new BAR.P;
> > procedure P is begin BAR_P; end;
> > end FOO;
> > --->%---
> >
> > Regards,
> > Markus
>
> You can change the last to
>
> procedure P renames BAR_P;
>
> But that's the best you can do. If you have an incomplete declaration (i.e. the declaration of P in the *spec* of FOO), you can't complete it with a generic instantiation---that's the rule. (I think he reason is that a generic instantiation is equivalent to a declaration of the instance followed by the body of the instance, and doing that here would mean you're declaring P twice, which isn't allowed. It can be argued that the language rules should be relaxed in this case, since it's tripped up more than one person, and offhand I don't see any complications that would arise if it were allowed.)
I just got reminded by Tucker Taft that there's a problem if P has parameters. The parameters aren't listed in a generic_instantiation:
package FOO is
procedure P (Param : in Integer; Param2 : out Integer);
end FOO;
package body FOO is
package BAR is new SOME_GENERIC_PACKAGE;
procedure P is new BAR.P;
end FOO;
This makes it less clear to the eye that the second P completes the first one. (This would especially be a problem if there is more than one P with different parameter profiles in the specification.) This makes it clearer:
package FOO is
procedure P (Param : in Integer; Param2 : out Integer);
end FOO;
package body FOO is
package BAR is new SOME_GENERIC_PACKAGE;
procedure New_P is new BAR.P;
procedure P (Param : in Integer; Param2 : out Integer)
renames New_P;
end FOO;
So there's a good reason why the rules are the way they are.
-- Adam
next prev parent reply other threads:[~2012-05-17 3:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-16 14:21 Declaring private packages to instantiate generics? Markus Schöpflin
2012-05-16 14:36 ` Adam Beneschan
2012-05-16 14:45 ` Markus Schöpflin
2012-05-17 1:24 ` Shark8
2012-05-17 3:37 ` Adam Beneschan [this message]
2012-05-21 8:06 ` Markus Schöpflin
2012-05-21 15:51 ` Simon Wright
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox