comp.lang.ada
 help / color / mirror / Atom feed
From: Phil Thornley <phil.jpthornley@googlemail.com>
Subject: Re: Trouble cutting loops with SPARK. Advice?
Date: Sun, 7 Mar 2010 03:43:12 -0800 (PST)
Date: 2010-03-07T03:43:12-08:00	[thread overview]
Message-ID: <f22c42d4-249f-4dab-bfc8-50a47d7647ed@b7g2000yqd.googlegroups.com> (raw)
In-Reply-To: m2y6i4s7hh.fsf@pushface.org

On 7 Mar, 11:20, Simon Wright <si...@pushface.org> wrote:
> Phil Thornley <phil.jpthorn...@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 ...

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



  reply	other threads:[~2010-03-07 11:43 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
2010-03-07 11:43     ` Phil Thornley [this message]
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