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=unavailable autolearn_force=no version=3.4.4 Path: border1.nntp.dca1.giganews.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!nntp-feed.chiark.greenend.org.uk!ewrotcd!reality.xs3.de!news.jacob-sparre.dk!loke.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Static_Predicate on array-types. Date: Mon, 21 Jul 2014 17:35:38 -0500 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: References: NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: loke.gir.dk 1405982138 26058 69.95.181.76 (21 Jul 2014 22:35:38 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Mon, 21 Jul 2014 22:35:38 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 Xref: number.nntp.dca.giganews.com comp.lang.ada:187766 Date: 2014-07-21T17:35:38-05:00 List-Id: "Robert A Duff" wrote in message news:wcc7g3a1fx4.fsf@shell01.TheWorld.com... > Shark8 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.