From: aio!dnsurber@eos.arc.nasa.gov (Douglas N. Surber)
Subject: Generic Instantiation as Subprogram Body?
Date: 8 Oct 92 18:00:47 GMT [thread overview]
Message-ID: <dnsurber.718567247@node_26400> (raw)
The following code is what I want to write. It doesn't work and I don't
like that!
generic
type T is range <>;
package P is
type U is private;
function "<" (l,r : U) return boolean;
function "<=" (l,r : U) return boolean;
function ">" (l,r : U) return boolean;
function ">=" (l,r : U) return boolean;
private
type U is new T; -- or whatever
end P;
package body P is
generic
with function op(l,r : T) return boolean;
function rel (l,r : U) return boolean;
-- the following doesn't work. declared function name hides the
-- generic actual.
function "<" is new rel("<");
function "<=" is new rel("<=");
function ">" is new rel(">");
function ">=" is new rel(">=");
function rel (l,r : U) return boolean is
begin
return op(l, r); -- or whatever
end rel;
end P;
Neither of the following kludges works since neither a rename nor a generic
instantiation is a subprogram body and a package body must have a subprogram
body for every subprogram spec in the package spec. The new function declared
in the second line is a different function from the one with the same name
and signature declared in the spec and so fails.
function lt (l,r : T) return boolean renames "<";
function "<" is new rel(lt);
function lt is new rel("<");
function "<" (l,r : U) return boolean renames lt;
You can't imagine how irritating it is to be told that there is no body for
function "<" and that function "<" has the same name and the same signature
as the previously declared function. "No kiddin'! You think that's an
accident? Stoopid machine!"
One thing that seems to work is to put one of the previous kludges in
the package spec. That sucks! The fact that the relational operators are
instances of a generic function is strictly an implementation detail.
What's more, I don't want the generic function rel to be part of the spec.
Of course the following works, but it's an even bigger kludge than the others
and its efficiency depends on the compiler's ability to optimize out a lot of
overhead.
function lt is new rel("<");
pragma inline (lt);
function "<" (l,r : U) return boolean is
begin
return lt (l, r);
end "<";
Three questions:
1) Is there a better way to accomplish this without changing the
package spec?
2) If not, why not? (What is the rationale, not what does the LRM say.)
3) Is this fixed in 9X? (hint, hint)
Douglas Surber
Lockheed
Houston, TX
next reply other threads:[~1992-10-08 18:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1992-10-08 18:00 Douglas N. Surber [this message]
-- strict thread matches above, loose matches on Subject: below --
1992-10-08 19:54 Generic Instantiation as Subprogram Body? dog.ee.lbl.gov!hellgate.utah.edu!caen!zaphod.mps.ohio-state.edu!hobbes.ph
1992-10-14 17:03 yale.edu!jvnc.net!netnews.upenn.edu!uofs!guinness.cs.uofs.edu!beidler
1992-10-15 8:50 darwin.sura.net!paladin.american.edu!news.univie.ac.at!hp4at!mcsun!uknet!
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox