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=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,ade418da030a5253 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!b7g2000yqd.googlegroups.com!not-for-mail From: Phil Thornley Newsgroups: comp.lang.ada Subject: Re: Trouble cutting loops with SPARK. Advice? Date: Sun, 7 Mar 2010 03:43:12 -0800 (PST) Organization: http://groups.google.com Message-ID: References: <4b92bb37$0$2342$4d3efbfe@news.sover.net> <484e7806-9242-4c20-a057-cbc34fd67f03@g28g2000yqh.googlegroups.com> NNTP-Posting-Host: 80.177.171.182 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1267962192 20011 127.0.0.1 (7 Mar 2010 11:43:12 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 7 Mar 2010 11:43:12 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: b7g2000yqd.googlegroups.com; posting-host=80.177.171.182; posting-account=Fz1-yAoAAACc1SDCr-Py2qBj8xQ-qC2q User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0),gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:9457 Date: 2010-03-07T03:43:12-08:00 List-Id: On 7 Mar, 11:20, Simon Wright wrote: > Phil Thornley writes: > > The problem is that the value of the variables that provide the loop > > bounds (in your code the variable Characters_To_Copy) can be changed > > within the loop, so any reference to Characters_To_Copy within an > > assertion in the loop means the *current* value, not the value that > > defined the loop bound. > > Would it have helped if Peter had said, instead of > > =A0 =A0 =A0 Characters_To_Copy : Line_Size_Type; > =A0 =A0begin > =A0 =A0 =A0 Result.Text :=3D Line_Type'(others =3D> ' '); > =A0 =A0 =A0 if Line'Length > Max_Line_Length then > =A0 =A0 =A0 =A0 =A0Characters_To_Copy :=3D Max_Line_Length; > =A0 =A0 =A0 else > =A0 =A0 =A0 =A0 =A0Characters_To_Copy :=3D Line'Length; > =A0 =A0 =A0 end if; > > this: > > =A0 =A0 =A0 Characters_To_Copy : constant Line_Size_Type > =A0 =A0 =A0 =A0 :=3D Line_Size_Type'Min (Line'Length, Max_Line_Length); > =A0 =A0begin > =A0 =A0 =A0 Result.Text :=3D Line_Type'(others =3D> ' '); > > And I'm sure one could eliminate the loop by proper slicing. Of course, > that would reduce the SPARK learning experience ... Well - he would have learned that it isn't valid SPARK :-) (All initialization values must be static and slices aren't allowed either) Cheers, Phil