comp.lang.ada
 help / color / mirror / Atom feed
From: hasan@ut-emx.uucp (David A. Hasan)
Subject: Re: factoring with generics
Date: 11 Mar 91 21:20:40 GMT	[thread overview]
Message-ID: <45441@ut-emx.uucp> (raw)
In-Reply-To: 45358@ut-emx.uucp

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 <f1> & <f2> differ only in one subprogram call ]

>It occurs to me that it might be wise to implement these
>as instances of one generic function (<g_f>, say) which takes the 
>crucial differing subprogram as a generic parameter.  
>To do this, I could:

>   1) put the GENERIC DECLARATION and BODY of <g_f> in the body of <p>.
>      In this case, the implementations of <f1> & <f2> would 
>      instantiate <g_f>.

>      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 <f1> as it
appears in the package spec.

Anyone know whether this is legal or not?
-- 
 |   David A. Hasan
 |   hasan@emx.utexas.edu 

  reply	other threads:[~1991-03-11 21:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1991-03-08 23:36 factoring with generics David A. Hasan
1991-03-11 21:20 ` David A. Hasan [this message]
1991-03-14  3:45   ` William Loftus
1991-03-15 17:39     ` David A. Hasan
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox