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!news.eternal-september.org!feeder.eternal-september.org!news.stack.nl!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: Exceptions in (dynamic) predicates Date: Sat, 2 Nov 2013 01:23:04 -0500 Organization: Jacob Sparre Andersen Research & Innovation Message-ID: References: <700ca98a-a6d6-47af-a7d6-fe23cf2729b2@googlegroups.com> NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: loke.gir.dk 1383373384 23853 69.95.181.76 (2 Nov 2013 06:23:04 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Sat, 2 Nov 2013 06:23:04 +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:17579 Date: 2013-11-02T01:23:04-05:00 List-Id: "Adam Beneschan" wrote in message news:700ca98a-a6d6-47af-a7d6-fe23cf2729b2@googlegroups.com... > On Thursday, October 31, 2013 2:52:36 PM UTC-7, Simon Wright wrote: >> A StackOverflow answer contains the following code: >> >> subtype XYZ is ABC >> with Dynamic_Predicate => >> ((XYZ.A in Positive) and >> (XYZ.B not in Positive)) or else raise Constraint_Error; >> >> (actually, the original didn't have the 'else', with unhelpful results :) >> >> I can't see where in the ARM "raise Constraint_Error" can be a >> (component of a) boolean expression? or is this a GNATism? > > Maybe it's AI12-0022? > > http://www.ada-auth.org/cgi-bin/cvsweb.cgi/ai12s/ai12-0022-1.txt > > Looks like it's a planned addition to Ada 202x. Well, actually it's an after-the-fact addition to Ada 2012. (AI12-0022-1 is a Binding Interpretation, not an Amendment 1.) We realized that we needed it at the last meeting before sending out the Standard wording, but we couldn't get the details right at the meeting and decided to look at it later. Within a few weeks after the meeting, we had figured out the appropriate semantics. The problem is that without it, you can't replace existing natural language text specifications (that is, comments) with preconditions and predicates, because the exception raised would change. That doesn't seem helpful. The Ada 2012 Rationale Epilogue discusses this (and the following) -- although you'll have to wait until next week for it to be on-line at ada-auth.org. Note that for a predicate, you really should use the new Predicate_Failure aspect rather than putting the exception in the predicate proper, because otherwise memberships and validity checks would raise the exception instead of returning the appropriate True or False answer. (That took a lot longer to work out, but that's less jarring as aspects can be added at any time and by implementers.) subtype XYZ is ABC with Dynamic_Predicate => (XYZ.A in Positive) and (XYZ.B not in Positive), Predicate_Failure => raise Constraint_Error; See the Rationale Epilogue for a better explanation that I can put here. Not sure exactly when GNAT will support Predicate_Failure (we only nailed it down at the June meeting), but I'd expect it to be soon. Randy.