comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Static_Predicate on array-types.
Date: Mon, 21 Jul 2014 17:35:38 -0500
Date: 2014-07-21T17:35:38-05:00	[thread overview]
Message-ID: <lqk4jq$pea$1@loke.gir.dk> (raw)
In-Reply-To: wcc7g3a1fx4.fsf@shell01.TheWorld.com

"Robert A Duff" <bobduff@shell01.TheWorld.com> wrote in message 
news:wcc7g3a1fx4.fsf@shell01.TheWorld.com...
> Shark8 <OneWingedShark@gmail.com> writes:
>
>> Is there any particular reason why we cannot put static-predicates on an
>> array-type, such as (e.g.) to ensure that some condition always holds?
>>
>> Example, we want an unbounded array, but to ensure the first index is
>> always 1:
>>     Type One_Based_Vector is Array(Positive Range <>) of Integer
>>       with Static_Predicate => One_Based_Vector'First = 1;
>
> What advantage would that have over using Dynamic_Predicate (or in GNAT,
> Predicate)?

Right: the point of Static_Predicate is that the subtype can be used in 
subtype choices and for loops. There is no such possibility for an array.

The other possible advantage is that a Static_Predicate has similar dynamic 
semantics to a constraint (a Dynamic_Predicate is just an assertion that 
might be made false without checking). Here, the effect is impractical to 
have for composite types; a lot of additional rules would be required - 
similar to the ones required for constraints. That is too much mechanism.

... > You might be able to guess from the discussion that I
> disagreed with the decision to have two aspects Static_Predicate and
> Dynamic_Predicate.

Yeah, you were wrong. :-)

> I preferred to have a single aspect Predicate, which
> is either static or dynamic depending on what the expression is.

Which is a maintenance hazard; it's really easy to write something that's 
not predicate-static (like "Mod") and prevent clients from using a subtype 
in case statements. If you're building reusable code, the problem might not 
show up for a long time, until some unrelated client upgrades to the latest 
version.

> Just like for "X: constant T := expression;", X is a static constant if
> the expression is static.

Yeah. Robert's latest issue show *that* is a maintenance hazard, at least if 
T is a real type. The solution proffered is to break the rules for static 
expressions - yuck. Two wrongs don't make a right.

                               Randy.




      reply	other threads:[~2014-07-21 22:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-17 19:43 Static_Predicate on array-types Shark8
2014-07-18 22:05 ` Robert A Duff
2014-07-21 22:35   ` Randy Brukardt [this message]
replies disabled

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