From: Martin <martin.dowie@btopenworld.com>
Subject: Re: Strategies with SPARK which does not support exceptions
Date: Fri, 18 Jun 2010 01:49:20 -0700 (PDT)
Date: 2010-06-18T01:49:20-07:00 [thread overview]
Message-ID: <28cc6b90-fce4-44e0-903e-9c1dd1b91f5a@c33g2000yqm.googlegroups.com> (raw)
In-Reply-To: bb33c110-b0d6-4d7a-b8b0-ab03d91562f3@y11g2000yqm.googlegroups.com
On Jun 18, 9:06 am, Phil Thornley <phil.jpthorn...@gmail.com> wrote:
> On 17 June, 16:33, Yannick Duchêne (Hibou57)
>
>
>
> <yannick_duch...@yahoo.fr> wrote:
> > Hello,
>
> > (This topic will probably not be the most exiting topic to some people).
>
> > When I use SPARK, or even when I don't use SPARK while I still have SPARK
> > design style in mind (even with Pascal which I still use), I have like any
> > one else, to forget about exceptions.
>
> > The only one thing which seems simple and clean enough I could figure, is
> > to use a Boolean variable, named “OK”, and a sequence of “if OK then”
> > statements. That is, execution of one sequence of statements, which set OK
> > to False is something goes wrong, and execute clean-up statements by the
> > way. Then a next sequence of statements wrapped in a “if OK then” which do
> > the same, and so on with next statements groups which are also wrapped in
> > a “if OK then” (as many as needed).
>
> > Although this seems clean and maintainable enough to me so far, I was
> > still wondering how other people deal with this (and may be by the way, I
> > may have comment about why my way could be bad in some way).
>
> > Note: a similar strategy may also obviously applies to fulfill the “only
> > one single exit point” requirement.
>
> > So, let us talk and comment about design strategies in this area (if
> > someones wish to).
>
> (Perhaps not an entirely serious suggestion, but...)
> The only way of interrupting a code sequence in SPARK is the exit
> statement for a loop, so one possibility might be to create a 'single
> pass' loop with an unconditional exit at the end.
>
> Unfortunately such an unconditional exit is illegal, so you have to
> use 'exit when True;'
>
> Also there may be flow errors for some or all of the 'exit when'
> statements (if the OK values only depend on the program inputs) - but
> here we can put an accept statement - which will usefully document
> that the loop is a not a real loop.
>
> --# accept F, 40, "This is a single pass loop.";
> OK := True;
> loop
> Some complicated code that might set OK;
> exit when not OK;
> Some more complicated code that might set OK;
> exit when not OK;
> Some more code;
> exit when True;
> end loop;
>
> :-)
>
> Cheers,
>
> Phil
No there's a fancy 'goto'! :-)
-- Martin
next prev parent reply other threads:[~2010-06-18 8:49 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-17 15:33 Strategies with SPARK which does not support exceptions Yannick Duchêne (Hibou57)
2010-06-17 17:11 ` Warren
2010-06-17 18:19 ` Yannick Duchêne (Hibou57)
2010-06-21 13:31 ` Warren
2010-06-21 14:10 ` Alexandre K
2010-06-17 19:54 ` Pascal Obry
2010-06-17 22:47 ` Peter C. Chapin
2010-06-18 6:07 ` Claude
2010-06-18 8:06 ` Phil Thornley
2010-06-18 8:49 ` Martin [this message]
2010-06-18 17:16 ` mockturtle
2010-06-18 21:51 ` Alexandre K
2010-06-22 17:01 ` Phil Clayton
2010-06-22 23:14 ` Claude
2010-06-23 16:22 ` Warren
2010-06-24 3:24 ` Claude
2010-06-28 13:14 ` Warren
2010-06-29 8:39 ` Stephen Leake
2010-06-29 20:05 ` Randy Brukardt
2010-06-29 20:49 ` Georg Bauhaus
2010-06-30 5:08 ` Simon Wright
2010-06-30 8:17 ` stefan-lucks
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox