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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c0d427d5f4af20f8 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!f14g2000cwb.googlegroups.com!not-for-mail From: "REH" Newsgroups: comp.lang.ada Subject: Re: generics in Ada 83 Date: 13 Sep 2005 11:53:36 -0700 Organization: http://groups.google.com Message-ID: <1126637616.954302.85630@f14g2000cwb.googlegroups.com> References: <1126617980.932226.320710@g43g2000cwa.googlegroups.com> NNTP-Posting-Host: 192.91.173.36 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1126637622 31655 127.0.0.1 (13 Sep 2005 18:53:42 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 13 Sep 2005 18:53:42 +0000 (UTC) In-Reply-To: User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.10) Gecko/20050716,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: f14g2000cwb.googlegroups.com; posting-host=192.91.173.36; posting-account=lnUIyw0AAACoRB2fMF2SFTIilm8F10q2 Xref: g2news1.google.com comp.lang.ada:4622 Date: 2005-09-13T11:53:36-07:00 List-Id: Jeffrey Carter wrote: > REH wrote: > > > > generic > > type X is private; > > with procedure Y(Z : in X); > > package Foo; > > > > I want to define a default for Y, but how can I without knowing X? > > Defaults are defined for subprograms by inserting "is Name" or "is <>" > before the semicolon (;): > > with procedure Y (Z : in X) is A; > > or > > with procedure Y (Z : in X) is <>; > > You can't use the former, since it requires a procedure A, visible at > the point of the generic, that matches Y. Since you don't know what X is > at the point of the generic, you can't have such a procedure. > > You can use the latter, which requires a procedure Y, visible at the > point of the instantiation. However, that's unlikely to be what you want. > > You can also use a 2-step instantiation: > > generic -- Outer > type X is private; > package Outer is > procedure Null_Proc (Z : in X); > > generic -- Inner > with procedure Y (Z : in X) is Null_Proc; > package Inner is > ... > end Inner; > end Outer; > > Such an approach complicates the process of instantiating the generic, > but may be OK if it results in an overall reduction in the complexity of > the instantiation process. If your generic has many formal subprograms, > but only a small percentage are likely to need explicit actuals, this > might be acceptable. > > However, if it's unlikely that a client will use all the services of the > package, and different clients will use different subsets of those > services, then you probably have a design problem. In such a case, you > probably want to redesign to have several packages that factor out the > likely subsets: several generics that provide the non-overlapping > subsets of the possible services, and perhaps some higher-level generics > that instantiate 2 or more of the non-overlapping subsets to provide > overlapping subsets. > Well I guess there is always a better way. Here is my actual problem. My team maintains a set of middleware services for various applications. We have a Client/Server package as part of this. It defines a header type for transmitting messages across TCP/IP. One application group has requested the ability to define their own header. There are certain pieces of information our software needs to know from the header, such as the message length. So I re-defined the package thus: generic type Header_Type is private; with function Get_Length(Header : in Header_Type) return Integer; with procedure Set_Length(Header : in out Header_Type; Length : in Integer); package Client_Server; This works fine for using most of the services in the package. But the thorn is the package provides a "synchronous send" feature that does a request/response type of transaction over a network. This requires several more fields to be present in the header and accessed at various times. Thus, I have added get and set subprograms for those. But I don't want a client application that does not use this feature to have to define stubs for all these. Which is where I am tried to find a way to "default" them. Thanks for your time and help. REH