comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: Trouble cutting loops with SPARK. Advice?
Date: Sun, 07 Mar 2010 11:20:58 +0000
Date: 2010-03-07T11:20:58+00:00	[thread overview]
Message-ID: <m2y6i4s7hh.fsf@pushface.org> (raw)
In-Reply-To: 484e7806-9242-4c20-a057-cbc34fd67f03@g28g2000yqh.googlegroups.com

Phil Thornley <phil.jpthornley@googlemail.com> 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 ...



  parent reply	other threads:[~2010-03-07 11:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-06 20:33 Trouble cutting loops with SPARK. Advice? Peter C. Chapin
2010-03-07 10:22 ` Phil Thornley
2010-03-07 11:04   ` Peter C. Chapin
2010-03-07 11:41     ` Phil Thornley
2010-03-07 11:20   ` Simon Wright [this message]
2010-03-07 11:43     ` Phil Thornley
2010-03-07 16:27       ` Simon Wright
replies disabled

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