From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!ut-emx!hasan From: hasan@ut-emx.uucp (David A. Hasan) Newsgroups: comp.lang.ada Subject: Re: factoring with generics Message-ID: <45441@ut-emx.uucp> Date: 11 Mar 91 21:20:40 GMT References: <45358@ut-emx.uucp> Organization: UTexas Center for Space Research List-Id: In article <45358@ut-emx.uucp> I wrote: >PACKAGE p IS > TYPE someType IS ...; > FUNCTION f1(arg1,arg2 : IN someType) RETURN someType; > FUNCTION f2(arg1,arg2 : IN someType) RETURN someType; >END p; [ where & differ only in one subprogram call ] >It occurs to me that it might be wise to implement these >as instances of one generic function (, say) which takes the >crucial differing subprogram as a generic parameter. >To do this, I could: > 1) put the GENERIC DECLARATION and BODY of in the body of

. > In this case, the implementations of & would > instantiate . > But of course, this is hogwash: generic instantiations > are *declarations* and cannot be used to define the > implementation. So, as an alternative... Or *is* it hogwash? This technique is used by Habermann & Perry in their book "Ada for Experienced Programmers". In fact, the LRM seems to indicate that a generic instantiation can be used as the implementation of a subprogram. (I reached this conclusion by threading my way through the BNF -- a technique I often use when I can't find an explicit discussion of my problems.) The DEC compiler objects to the presence of generic instantiations such as FUNCTION f1 is NEW g_f( ... ); on the basis that it constitutes a redclaration of as it appears in the package spec. Anyone know whether this is legal or not? -- | David A. Hasan | hasan@emx.utexas.edu