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,ade418da030a5253 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!feeder1.cambriumusenet.nl!feed.tweaknews.nl!85.158.31.10.MISMATCH!newsfeed-0.progon.net!progon.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.straub-nv.de!feeder.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Trouble cutting loops with SPARK. Advice? Date: Sun, 07 Mar 2010 11:20:58 +0000 Organization: A noiseless patient Spider Message-ID: References: <4b92bb37$0$2342$4d3efbfe@news.sover.net> <484e7806-9242-4c20-a057-cbc34fd67f03@g28g2000yqh.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Sun, 7 Mar 2010 11:20:59 +0000 (UTC) Injection-Info: feeder.eternal-september.org; posting-host="KCXegvZb5vh43D+f3BR6Ew"; logging-data="23386"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19y/V2N9QaxFckND5V40VOS2krG+WU2b4w=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (darwin) Cancel-Lock: sha1:CXOYZ+7rGagoQiAV8n/EzgPYCsA= sha1:5P/Pc+62WZo8+kdrgmc3aiQelto= Xref: g2news1.google.com comp.lang.ada:9455 Date: 2010-03-07T11:20:58+00:00 List-Id: 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 Characters_To_Copy : Line_Size_Type; begin Result.Text := Line_Type'(others => ' '); if Line'Length > Max_Line_Length then Characters_To_Copy := Max_Line_Length; else Characters_To_Copy := Line'Length; end if; this: Characters_To_Copy : constant Line_Size_Type := Line_Size_Type'Min (Line'Length, Max_Line_Length); begin Result.Text := Line_Type'(others => ' '); And I'm sure one could eliminate the loop by proper slicing. Of course, that would reduce the SPARK learning experience ...