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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,cea03ed275aa3d28 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!news2.google.com!atl-c05.usenetserver.com!news.usenetserver.com!news-out.octanews.net!teal.octanews.net!statler.nntpserver.com!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Question about generics. Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <7Q2qg.812592$084.507058@attbi_s22> Date: Tue, 4 Jul 2006 09:48:59 +0200 Message-ID: <1rpnsptk3y97q$.1585mjoskc36l.dlg@40tude.net> NNTP-Posting-Date: 04 Jul 2006 09:48:59 MEST NNTP-Posting-Host: b16859b8.newsread2.arcor-online.net X-Trace: DXC=hjUQ[_QO=jbP8MgCCFiJ[lQ5U85hF6f;djW\KbG]kaMhGSi?jHD8GO`U_?@XN_>FTa[6LHn;2LCVn7enW;^6ZC`dIXm65S@:3>o X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:5455 Date: 2006-07-04T09:48:59+02:00 List-Id: On Mon, 3 Jul 2006 19:08:07 -0500, Randy Brukardt wrote: > "Dmitry A. Kazakov" wrote in message > news:dv4t30a6porw.1r47tofvyu5ws$.dlg@40tude.net... > ... >> Right. But it is the problem of Ada, that "static Positive" cannot be >> expressed as a [formal] type. If that were possible then the generic unit >> could be checked before instantiation. There are also other cases where >> that would be useful. For example, for forcing constant folding at compile >> time (necessary for statically dimensioned values.) > > It's not a problem, it's a feature. Repeat after me: a generic is not a > macro. A generic is not a macro. A generic is not a macro. Got it yet?? ;-) No, they are, even if bodies are shared! (:-)) > The legality of a generic body never, ever depends on the actual values used > in an instantiation. The legality of a generic spec rarely depends on the > actual values. Yes, therefore Size cannot be just Positive. Legality of "type X mod Size" does not depend on the value of Size, it does on whether the value is static. [ OK, that could be changed as well, but it is another story. ] > In any case, allowing some sort of static generic parameter would completely > prevent any possibility of generic code sharing. It's unlikely that the > language would be changed in such a way. > > (If you don't understand why, just consider putting the bit locations for > various types as formal parameters. How would you implement sharing then?) It is definitely possible. Though it might become utterly inefficient. Anything that determines legality must be in the contract. So the constraints have to be passed from *outside*. For example, if the static parameters are used in case within the body: case Something is when Param1 => when Param2 => when Param3 => end case then the constraint that Params do not intersect and cover all choices shall be in some other formal parameter of the generic unit. [Universal sets, range would probably be required to express such things] Without such parameter+constraint generic would spit out an error, that choices are wrong. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de