comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Question about generics.
Date: Tue, 4 Jul 2006 09:48:59 +0200
Date: 2006-07-04T09:48:59+02:00	[thread overview]
Message-ID: <1rpnsptk3y97q$.1585mjoskc36l.dlg@40tude.net> (raw)
In-Reply-To: FPGdnfVKb8amLDTZnZ2dnUVZ_vOdnZ2d@megapath.net

On Mon, 3 Jul 2006 19:08:07 -0500, Randy Brukardt wrote:

> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> 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



  reply	other threads:[~2006-07-04  7:48 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-02 16:08 Question about generics Peter C. Chapin
2006-07-02 18:49 ` Martin Krischik
2006-07-03  6:30 ` Jeffrey R. Carter
2006-07-03 10:33   ` Peter C. Chapin
2006-07-03 11:42     ` Jean-Pierre Rosen
2006-07-03 16:44     ` Pascal Obry
2006-07-04  1:09       ` Peter C. Chapin
2006-07-04  6:17         ` M E Leypold
2006-07-04 10:48           ` Peter C. Chapin
2006-07-03 20:03     ` Jeffrey R. Carter
2006-07-03 20:18       ` Dmitry A. Kazakov
2006-07-04  0:08         ` Randy Brukardt
2006-07-04  7:48           ` Dmitry A. Kazakov [this message]
2006-07-04  0:43         ` Jeffrey R. Carter
2006-07-03  9:46 ` Martin Krischik
2006-07-04 13:29 ` Stephen Leake
2006-07-05 12:08   ` Dmitry A. Kazakov
  -- strict thread matches above, loose matches on Subject: below --
1993-09-02 17:45 question " Stef  Van Vlierberghe
1993-08-12 15:18 Robert I. Eachus
1993-08-11 18:48 cis.ohio-state.edu!magnus.acs.ohio-state.edu!math.ohio-state.edu!howland.
1993-08-11  0:25 agate!howland.reston.ans.net!europa.eng.gtefsd.com!darwin.sura.net!seas.g
1993-08-10 15:53 Robert I. Eachus
1993-08-09 21:29 Kenneth Anderson
1989-05-29 20:54 Question " "14827_DAVID PAPAY"
1989-05-29  7:02 "Jonathan B. Owen"
replies disabled

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