comp.lang.ada
 help / color / mirror / Atom feed
From: Andrew Shvets <andrew.shvets@gmail.com>
Subject: Re: Instantiating package problems
Date: Wed, 6 Jan 2016 20:42:23 -0800 (PST)
Date: 2016-01-06T20:42:23-08:00	[thread overview]
Message-ID: <690510c8-f5ed-4bcf-b937-f65ef293f23c@googlegroups.com> (raw)
In-Reply-To: <n6j3e0$51q$1@dont-email.me>

On Wednesday, January 6, 2016 at 8:07:45 AM UTC-5, G.B. wrote:
> On 06.01.16 06:00, Andrew Shvets wrote:
> > On Tuesday, January 5, 2016 at 11:52:00 PM UTC-5, Anh Vo wrote:
> 
> >> The preconditions and postconditions are controlled by pragma Assertion_Policy. Thus, pragma Assertion_Policy(Check) must be added at the top of the package specification. Absent of this pragma is equivalent to pragma Assertion_Policy (Ignore). That means these conditions are ignored. By the way, ASSERTION_ERROR exception would be raised instead of CONSTRAINT_ERROR.
> >
> > This is how the body looks like now:
> > http://pastebin.com/Mt0E0HAD
> >
> > I'm still getting a constraint error.
> >
> 
> You should see something like this, after adding Assertion_Policy
> in the way Anh Vo has described:
> 
> raised SYSTEM.ASSERTIONS.ASSERT_FAILURE : failed precondition from 
> shvets.ada:15
> 
> If you know that what Dmitry has explained is true,
> you could state it as a workable approximation,
> so that clients of the package know what to do when
> the programmers are not certain about all implications,
> practical and theoretical, of predefined division "/"
> in Input1/Input2, Integer'[Base']Range, and more:
> 
> 
>     Extra_Value : constant Boolean :=
>       not (Integer'Last = -Integer'First);
> 
>     function Division
>       (Input1 : in Integer;
>        Input2 : in Integer)
>       return Integer
>     with
>       Pre =>
>         Input2 /= 0
>         and
>         (if Extra_Value
>          then not (Input1 = Integer'First and Input2 = -1)),
>       Post =>
>         Input1/Input2 in Integer'Range
>         and
>         Division'Result = Input1/Input2;

It makes sense in principle.  I've seen something similar in erlang where you could check if one of the inputs is an integer, float, etc.

  reply	other threads:[~2016-01-07  4:42 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-03 18:40 Instantiating package problems Andrew Shvets
2016-01-03 20:27 ` Georg Bauhaus
2016-01-03 21:21   ` Andrew Shvets
2016-01-03 21:04 ` Jeffrey R. Carter
2016-01-03 21:27   ` Andrew Shvets
2016-01-03 22:39     ` Jeffrey R. Carter
2016-01-03 22:08 ` Bob Duff
2016-01-04  0:07   ` Andrew Shvets
2016-01-04  0:30     ` Andrew Shvets
2016-01-04 13:43       ` G.B.
2016-01-04 14:23       ` Brian Drummond
2016-01-04 20:49     ` Anh Vo
2016-01-04 21:10       ` Dmitry A. Kazakov
2016-01-04 22:39         ` Anh Vo
2016-01-05  1:42           ` Anh Vo
2016-01-05  7:35           ` Dmitry A. Kazakov
2016-01-06  2:46       ` Andrew Shvets
2016-01-06  8:53         ` Dmitry A. Kazakov
2016-01-06  3:30       ` Andrew Shvets
2016-01-06  4:51         ` Anh Vo
2016-01-06  4:54           ` Anh Vo
2016-01-06  5:00           ` Andrew Shvets
2016-01-06  5:07             ` Anh Vo
2016-01-07  4:41               ` Andrew Shvets
2016-01-07  5:41                 ` Anh Vo
2016-01-09 20:14                   ` Andrew Shvets
2016-01-10 19:43                     ` Andrew Shvets
2016-01-10 21:38                       ` Jeffrey R. Carter
2016-01-10 21:50                       ` Georg Bauhaus
2016-01-10 21:58                         ` Andrew Shvets
2016-01-06 13:07             ` G.B.
2016-01-07  4:42               ` Andrew Shvets [this message]
2016-01-06 14:25           ` Bob Duff
2016-01-06 23:48             ` Anh Vo
replies disabled

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