At 04:05 PM 11/24/98 -0800, AdaWorks wrote:
> Mr. Mize wants to implement a
> object.method(parameter list)
>syntax. This can be done by combining a generic with private package where
>the tagged type is in the private part of the package specification. The
>actual object would be declared in the body.
>Even though we can do this in Ada, it is probably a contrivance to accomodate
>some defensive notion of syntax rather than a model of good design or
Slavish use of this idiom just for notational purity would be a bad idea.
But as your example shows, stacks are one of the cases in Ada where generic
package instances are often the best model for some object classes. You can
use generic formal parameters and subprograms to allow type extension, and
generic formal package parameters can be used to pass any package from the
class as a parameter.
Note that the "is <>;" default on formal generic subprograms is the one
instance of run-time polymorphism in Ada 83, although I would never
recommend using it just to obtain that effect. The run-time elaboration of
"is <>" is more of a pain for compiler vendors than anything else:
Generics are instantiated at run-time, and "is <>" matches the matching
subprogram statically enclosing the point of instantiation. (See RM
12.6(15).) It is always possible to figure out the (static) parameter and
result profile to be matched for every textual generic instantiation at
compile time, and which delaration will correspond to it. But it can be
the case that the actual subprogram created by that text to be called
cannot be determined until run-time. In particular, the default parameter
values may not be known until the instantiation is elaborated.
Robert I. Eachus
function Message (Text: in Clever_Ideas) return Better_Ideas is...