From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 8 Oct 92 18:00:47 GMT From: aio!dnsurber@eos.arc.nasa.gov (Douglas N. Surber) Subject: Generic Instantiation as Subprogram Body? Message-ID: List-Id: 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