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: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!gandalf.srv.welterde.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Ada 2012 Constraints (WRT an Ada IR) Date: Tue, 29 Nov 2016 17:52:18 -0600 Organization: JSA Research & Innovation Message-ID: References: NNTP-Posting-Host: rrsoftware.com X-Trace: franka.jacob-sparre.dk 1480463482 2707 24.196.82.226 (29 Nov 2016 23:51:22 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Tue, 29 Nov 2016 23:51:22 +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: news.eternal-september.org comp.lang.ada:32525 Date: 2016-11-29T17:52:18-06:00 List-Id: "Shark8" wrote in message news:c06ee4e6-d616-4e01-ba2e-cb111a81f6f6@googlegroups.com... >So, with Ada 2012 we gained some really nice possibilities with the way to >express constraints, the >downside is that there's now a fairly wide range of ways to express >constraints on types. Obviously >these differences must be accounted for, but the are functionally >equivalent, for example: > >Subtype P0 is Natural range Natural'Succ(Natural'First)..Natural'Last; >Subtype P1 is Integer range 1..Integer'Last; >Subtype P2 is Integer with Static_Predicate => P2 in 1..Integer'Last or >else raise Constraint_Error; >Subtype P3 is Integer with > Static_Predicate => P3 in 1..Integer'Last, > Predicate_Failure => raise Constraint_Error; > >Now, these should be generally the same way of writing the same thing (ie >"Positive") -- though > I'm not completely certain that this is the case in terms of subtle > semantics (am I missing something?) P2 is different than the others when used in a membership: Obj in P2 would raise Constraint_Error rather than return False (like the others) if Obj has the value 0. It's not recommended. P0 and P1 are more likely to be optimized by a compiler (just because of the many years of history). Perhaps P3 will catch up, but I wouldn't hold my breath on that. Randy.