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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.31.154.65 with SMTP id c62mr69278048vke.8.1452370456418; Sat, 09 Jan 2016 12:14:16 -0800 (PST) X-Received: by 10.182.231.229 with SMTP id tj5mr532232obc.13.1452370456381; Sat, 09 Jan 2016 12:14:16 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!6no3958969qgy.0!news-out.google.com!l1ni8673igd.0!nntp.google.com!h5no2305964igh.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 9 Jan 2016 12:14:16 -0800 (PST) In-Reply-To: <2ae043b6-e745-4f27-a9ab-cc183a25ca56@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2601:18f:900:8350:ba86:87ff:fed6:5907; posting-account=3pYsyQoAAACcI-ym7XtMOI2PDU8gRZS5 NNTP-Posting-Host: 2601:18f:900:8350:ba86:87ff:fed6:5907 References: <7dcd49f3-b04f-4ea3-b431-5c27f73b9afe@googlegroups.com> <87poxixqmy.fsf@theworld.com> <112f5e6c-35c1-483a-b8dd-24f5f76dc6ce@googlegroups.com> <084197af-8e37-4250-a083-b45bd9ab4609@googlegroups.com> <5a81226f-e719-4ca8-8cbc-d02cf4ab56e7@googlegroups.com> <768bb8bd-ed12-4235-a663-fa71fcb42795@googlegroups.com> <2ae043b6-e745-4f27-a9ab-cc183a25ca56@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Instantiating package problems From: Andrew Shvets Injection-Date: Sat, 09 Jan 2016 20:14:16 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: news.eternal-september.org comp.lang.ada:29069 Date: 2016-01-09T12:14:16-08:00 List-Id: On Thursday, January 7, 2016 at 12:41:33 AM UTC-5, Anh Vo wrote: > On Wednesday, January 6, 2016 at 8:41:38 PM UTC-8, Andrew Shvets wrote: > > On Wednesday, January 6, 2016 at 12:07:15 AM UTC-5, Anh Vo wrote: > > > On Tuesday, January 5, 2016 at 9:00:50 PM UTC-8, Andrew Shvets wrote: > > > > On Tuesday, January 5, 2016 at 11:52:00 PM UTC-5, Anh Vo wrote: > > > > > On Tuesday, January 5, 2016 at 7:31:00 PM UTC-8, Andrew Shvets wr= ote: > > > > > > On Monday, January 4, 2016 at 3:49:32 PM UTC-5, Anh Vo wrote: > > > > > > > On Sunday, January 3, 2016 at 4:07:30 PM UTC-8, Andrew Shvets= wrote: > > > > > > > > Hi Bob, > > > > > > > >=20 > > > > > > > > Thanks for writing back. This is the entire example: > > > > > > > > http://pastebin.com/GEJT3WzL > > > > > > > =20 > > > > > > > Just recommend to add a precondition to function Division as = shown below. By the way, this feature is part of latest Ada (Ada 2012). In = addition, you should think about adding precondition to other operations su= ch as Addition where Input1 + Input2 <=3D Integer'Last and Input1 + Input2 = >=3D Integer'Last.=20 > > > > > > >=20 > > > > > > > function Division( > > > > > > > Input1 : in Integer; > > > > > > > Input2 : in Integer) > > > > > > > return Integer > > > > > > > with pre =3D> Input2 /=3D 0; > > > > > > >=20 > > > > > > > Anh Vo > > > > > >=20 > > > > > > I'm not sure that that worked. I added it to my ads file and a= fter compilation and then re-running the application, this is what I got: > > > > > >=20 > > > > > > .... > > > > > >=20 > > > > > > Division: 4 > > > > > >=20 > > > > > >=20 > > > > > > raised CONSTRAINT_ERROR : calculator.adb:33 divide by zero > > > > > >=20 > > > > > > Shouldn't the division function been prevented from running the= actual division operation beforehand? > > > > >=20 > > > > > The preconditions and postconditions are controlled by pragma Ass= ertion_Policy. Thus, pragma Assertion_Policy(Check) must be added at the to= p of the package specification. Absent of this pragma is equivalent to prag= ma Assertion_Policy (Ignore). That means these conditions are ignored. By t= he way, ASSERTION_ERROR exception would be raised instead of CONSTRAINT_ERR= OR. > > > >=20 > > > > This is how the body looks like now: > > > > http://pastebin.com/Mt0E0HAD > > > >=20 > > > > I'm still getting a constraint error. > > >=20 > > > I only saw the pragma placed inside the package body. It should be pl= aced in the package specification. > >=20 > > Alright, I put the pragma before each package keyword (in the body and = the declaration) and this is what I got: > >=20 > > $ gnatmake -g main.adb > > gcc -c -g main.adb > > calculator.ads:5:01: pragma "assertion_policy" is not in declarative pa= rt or package spec > > gnatmake: "main.adb" compilation error >=20 > what I meant was on top of the package specification as shown below. >=20 > pragma Assertion_Policy (Check); > with Ada.Text_IO; >=20 > package Calculator is > --... > end Calculator; Got, thanks, it works now. And NOW I better understand how the constructor and destructor works in the= Ada language. Before, I was coming from a C++ perspective and looking at = it while nothing was making any sense.