comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Exceptions in (dynamic) predicates
Date: Sat, 2 Nov 2013 01:23:04 -0500
Date: 2013-11-02T01:23:04-05:00	[thread overview]
Message-ID: <l525o8$n9d$1@loke.gir.dk> (raw)
In-Reply-To: 700ca98a-a6d6-47af-a7d6-fe23cf2729b2@googlegroups.com

"Adam Beneschan" <adambeneschan@aol.com> 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.


  reply	other threads:[~2013-11-02  6:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-31 21:52 Exceptions in (dynamic) predicates Simon Wright
2013-10-31 23:34 ` Adam Beneschan
2013-11-02  6:23   ` Randy Brukardt [this message]
2013-11-04 16:20     ` Adam Beneschan
2013-11-21 23:48       ` Randy Brukardt
replies disabled

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