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!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newscon06.news.prodigy.com!newscon02.news.prodigy.com!prodigy.net!cyclone.swbell.net!bos-service1.raytheon.com!dfw-service2.ext.ray.com.POSTED!53ab2750!not-for-mail From: Jeffrey Carter User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: generics in Ada 83 References: <1126617980.932226.320710@g43g2000cwa.googlegroups.com> In-Reply-To: <1126617980.932226.320710@g43g2000cwa.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Tue, 13 Sep 2005 09:56:51 -0700 NNTP-Posting-Host: 147.24.111.90 X-Complaints-To: news@ext.ray.com X-Trace: dfw-service2.ext.ray.com 1126630613 147.24.111.90 (Tue, 13 Sep 2005 11:56:53 CDT) NNTP-Posting-Date: Tue, 13 Sep 2005 11:56:53 CDT Organization: Raytheon Company Xref: g2news1.google.com comp.lang.ada:4617 Date: 2005-09-13T09:56:51-07:00 List-Id: 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. -- Jeffrey Carter "Now go away or I shall taunt you a second time." Monty Python and the Holy Grail E-mail: jeffrey_r_carter-nr [commercial-at] raytheon [period | full stop] com