From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,e646052dc594401f X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!c10g2000yqi.googlegroups.com!not-for-mail From: mockturtle Newsgroups: comp.lang.ada Subject: Re: Strategies with SPARK which does not support exceptions Date: Fri, 18 Jun 2010 10:16:49 -0700 (PDT) Organization: http://groups.google.com Message-ID: <610aab02-26cd-4d66-9b45-ebdee71c8aad@c10g2000yqi.googlegroups.com> References: <28cc6b90-fce4-44e0-903e-9c1dd1b91f5a@c33g2000yqm.googlegroups.com> NNTP-Posting-Host: 93.37.245.120 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1276881409 19896 127.0.0.1 (18 Jun 2010 17:16:49 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 18 Jun 2010 17:16:49 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: c10g2000yqi.googlegroups.com; posting-host=93.37.245.120; posting-account=9fwclgkAAAD6oQ5usUYhee1l39geVY99 User-Agent: G2/1.0 X-HTTP-UserAgent: Opera/9.80 (X11; Linux i686; U; en) Presto/2.2.15 Version/10.10,gzip(gfe) Xref: g2news1.google.com comp.lang.ada:11815 Date: 2010-06-18T10:16:49-07:00 List-Id: On Jun 18, 10:49=A0am, Martin wrote: > (snip) > > OK :=3D True; > > loop > > =A0 =A0Some complicated code that might set OK; > > =A0 =A0exit when not OK; > > =A0 =A0Some more complicated code that might set OK; > > =A0 =A0exit when not OK; > > =A0 =A0Some more code; > > =A0 =A0exit 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 :=3D 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; <> Deallocate_Memory; <> Close_File; <> 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.