comp.lang.ada
 help / color / mirror / Atom feed
From: mockturtle <framefritti@gmail.com>
Subject: Re: Strategies with SPARK which does not support exceptions
Date: Fri, 18 Jun 2010 10:16:49 -0700 (PDT)
Date: 2010-06-18T10:16:49-07:00	[thread overview]
Message-ID: <610aab02-26cd-4d66-9b45-ebdee71c8aad@c10g2000yqi.googlegroups.com> (raw)
In-Reply-To: 28cc6b90-fce4-44e0-903e-9c1dd1b91f5a@c33g2000yqm.googlegroups.com

On Jun 18, 10:49 am, Martin <martin.do...@btopenworld.com> wrote:
> (snip)
> > 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

Well, I do not know if 'goto's are allowed in SPARK, but that is the
solution that sometimes I use when I need to write code in the-
language-whose-name-is-a-single-letter :-).  I know that it could
sound heretical, but this is one of the two cases where, I believe,
using goto is not so bad.  I am thinking something like

procedure Very_Complex_Stuff (OK : out Boolean) is
begin
  OK := True; -- Be optimistic :-)
  Open_some_file (OK);
  if not OK then
    goto Exit_now;
  end if;

  Allocate_Some_Memory (OK);
  if not OK then
    goto Undo_Open;
  end if;

  Contact_DB (OK);
  if not OK then
    goto Undo_Mem;
  end if;

  goto Exit_Now;

<<Undo_Mem>>
   Deallocate_Memory;

<<Undo_Open>>
   Close_File;

<<Exit_Now>>
end;

I agree that this will not win the prize for the best code ever, but
if you choose your labels with care it can turn out an acceptable
solution.





  reply	other threads:[~2010-06-18 17:16 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
2010-06-18 17:16     ` mockturtle [this message]
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