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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,da5197b9dca0ed40 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder.news-service.com!85.214.198.2.MISMATCH!eternal-september.org!.POSTED!not-for-mail From: Colin Paul Gloster Newsgroups: comp.lang.ada Subject: Re: Processing array subsections, a newbie question. Date: Mon, 14 Jun 2010 19:23:24 +0100 Organization: A noiseless patient Spider Message-ID: References: <4c13db30$0$2391$4d3efbfe@news.sover.net> Reply-To: Colin Paul Gloster Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Injection-Date: Mon, 14 Jun 2010 18:22:54 +0000 (UTC) Injection-Info: mx01.eternal-september.org; posting-host="kheEuXGHhE2Z5eF1gAST+A"; logging-data="16567"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19qyS4kGGMRhTj4DWoWVCklJ461DscyXzOO3p21tRYN5g==" User-Agent: Alpine 2.00 (LRH 1167 2008-08-23) In-Reply-To: <4c13db30$0$2391$4d3efbfe@news.sover.net> Cancel-Lock: sha1:WCr/q5zfKuCMmpgIL226xQPIgiQ= X-X-Sender: Colin_Paul@64bit-RedHat-Enterprise-Linux6beta Xref: g2news1.google.com comp.lang.ada:11719 Date: 2010-06-14T19:23:24+01:00 List-Id: On Sat, 12 Jun 2010, Peter C. Chapin sent: |------------------------------------------------------------------------------| |"[..] | | | |I want to invoke this procedure repeatedly on a particular buffer such that | |each invocation picks up where the previous invocation left off. For example | | | |Ok : Boolean := True; | |Index_Fst : Natural := Buffer'First; | |Index_Lst : Natural; | |... | | | |while Ok and Index_Fst <= Buffer'Last loop | | Do_Something(Buffer, Index_Fst, Index_Lst, Ok); | | Index_Fst := Index_Lst + 1; | |end loop; | | | |The problem with this code is that the assignment to Index_Fst inside the loop| |might raise Constraint_Error if Index_Lst = Buffer'Last after Do_Something | |finishes. I can work around this problem but my solutions tend to be rather | |ungainly looking. Surely there must be an easy way to handle this. | | | |Peter" | |------------------------------------------------------------------------------| You seemed to dislike the good idea of using different ranges for the cursors and the array mentioned elsewhere in this thread. So how about something like ... Index_Lst : integer := Buffer'First-1; --Hmm, perhaps I have merely --moved your disliked extra 1. ... while Ok and Index_Lst + 1 <= Buffer'Last loop Index_Fst := Index_Lst + 1; Do_Something(Buffer, Index_Fst, Index_Lst, Ok); end loop; ? It is a pity that I have introduced code cloning, but looping without sticking to predominant forms can have this consequence in any language I can think of (well, just the languages which have already been defined, that is, excluding languages we can devise). I really do not approve of the names Index_Fst and Index_Lst. How many people reading this have still not noticed Index_Fst is not in this version's condition? Be candid. I wish Ada success on student satellites! Regards, Colin Paul