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 02:22:43 -0800 (PST)
Date: 2010-03-07T02:22:43-08:00	[thread overview]
Message-ID: <484e7806-9242-4c20-a057-cbc34fd67f03@g28g2000yqh.googlegroups.com> (raw)
In-Reply-To: 4b92bb37$0$2342$4d3efbfe@news.sover.net

Peter,

> I get the feeling there is a trick here that I'm overlooking. Is my code
> wrong? It looks okay to me. :)

Your code is OK and yes there is something that you are probably
overlooking.

It's not really a 'trick' - more an oddity of the language for proving
code in 'for' loops that have range constraints.  (Loops like that are
the one exception to the SPARK rule that there are no anonymous
subtypes.)

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.  The Examiner doesn't check to see whether
Characters_To_Copy is changed within the loop (it just assumes that it
might be changed), so in this case you have to state that it is
unchanged in the loop assertion.

SPARK therefore supplies a notation for the value of any variable on
entry to a loop - append % to the name - so Characters_To_Copy% within
a proof context in the loop means the value of Characters_To_Copy on
entry to the loop.

The loop assertion that works for the code in your message is:
         --# assert I >= 1
         --#  and   Characters_To_Copy <= Line'Length
         --#  and   Characters_To_Copy = Characters_To_Copy%;
placed at the beginning of the loop.

Cheers,

Phil



  reply	other threads:[~2010-03-07 10:22 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 [this message]
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
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