comp.lang.ada
 help / color / mirror / Atom feed
* Static_Predicate on array-types.
@ 2014-07-17 19:43 Shark8
  2014-07-18 22:05 ` Robert A Duff
  0 siblings, 1 reply; 3+ messages in thread
From: Shark8 @ 2014-07-17 19:43 UTC (permalink / raw)


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;

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Static_Predicate on array-types.
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Robert A Duff @ 2014-07-18 22:05 UTC (permalink / raw)


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)?

If you want to know the rationale for the predicate rules, take a look
at the AI that introduced them:

http://www.ada-auth.org/cgi-bin/cvsweb.cgi/ai05s/ai05-0153-3.txt

which I wrote.  You might be able to guess from the discussion that I
disagreed with the decision to have two aspects Static_Predicate and
Dynamic_Predicate.  I preferred to have a single aspect Predicate, which
is either static or dynamic depending on what the expression is.
Just like for "X: constant T := expression;", X is a static constant if
the expression is static.

There's a GNAT-specific aspect Predicate, which is equivalent to
Static_Predicate if that would be legal, and Dynamic_Predicate
otherwise.

- Bob

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Static_Predicate on array-types.
  2014-07-18 22:05 ` Robert A Duff
@ 2014-07-21 22:35   ` Randy Brukardt
  0 siblings, 0 replies; 3+ messages in thread
From: Randy Brukardt @ 2014-07-21 22:35 UTC (permalink / raw)


"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.




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-07-21 22:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox