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=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,421f00454ed1208d X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!x1g2000prh.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: SPARK - runtime checks question Date: Fri, 19 Jun 2009 11:33:32 -0700 (PDT) Organization: http://groups.google.com Message-ID: <14f911e0-bd4c-4068-bae7-3d234cbed652@x1g2000prh.googlegroups.com> References: <8d79ac48-d35d-4717-aca3-68f036de0de3@f16g2000vbf.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1245436413 8845 127.0.0.1 (19 Jun 2009 18:33:33 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 19 Jun 2009 18:33:33 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: x1g2000prh.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:6545 Date: 2009-06-19T11:33:32-07:00 List-Id: On Jun 19, 8:26=A0am, Maciej Sobczak wrote: > Consider the following: > > -- my_package.ads: > package My_Package is > =A0 =A0function Distance (X : in Natural; Y : in Natural) return Natural; > end My_Package; > > -- my_package.adb: > package body My_Package is > > =A0 =A0function Distance (X : in Natural; Y : in Natural) return Natural > =A0 =A0is > =A0 =A0 =A0 Result : Natural; > =A0 =A0begin > =A0 =A0 =A0 if X > Y then > =A0 =A0 =A0 =A0 =A0Result :=3D X - Y; =A0 =A0// line 8 > =A0 =A0 =A0 else > =A0 =A0 =A0 =A0 =A0Result :=3D Y - X; =A0 =A0// line 10 > =A0 =A0 =A0 end if; > =A0 =A0 =A0 return Result; > =A0 =A0end Distance; > > end My_Package; Apologies in advance for answering a question you didn't ask, but... any reason not to simply return abs(X-Y)? If you're thinking that the result of X-Y will raise a Constraint_Error if it's negative---it won't. (At least not in Ada. I don't know much about SPARK---it wouldn't raise Constraint_Error there either, would it?) -- Adam