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 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: "G.B." Newsgroups: comp.lang.ada Subject: Re: Substrings as argument to procedures/functions Date: Wed, 13 Apr 2016 13:22:38 +0200 Organization: A noiseless patient Spider Message-ID: References: <2055a188-fb5f-496a-ab37-b25d81cebe1b@googlegroups.com> Reply-To: nonlegitur@futureapps.de Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 13 Apr 2016 11:19:19 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="b96887e80893c84a90c3007226ca0d1c"; logging-data="19616"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/vE7g7GbGfswjOHzHmltZRtEDdhz060i4=" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 In-Reply-To: <2055a188-fb5f-496a-ab37-b25d81cebe1b@googlegroups.com> Cancel-Lock: sha1:BhzA2//D6aYRppi2MiqZOIarMM0= Xref: news.eternal-september.org comp.lang.ada:30092 Date: 2016-04-13T13:22:38+02:00 List-Id: On 12.04.16 10:25, reinkor wrote: > Dear All, > > I believed that if a substring is an argument to a subroutine, > then its "range" would start at 1 (and not inherited from the calling program). > But this seems not to be the case. > Is this correct? And in case, is it "good" ? :-) It is a good idea, I think, not to be mislead by programming languages that don't have expressions for iteration at all, nor "sequence types", only emulations. That these are prone to errors has been mentioned in this thread. Consider for K in A'Range loop ... A(K) ... end loop; or, more recently found in Ada, for El of A loop ... El ... end loop; This most frequently used loop that does sequence processing does not refer to any specific bound on A. No assumptions, or checks are being programmed. It is safe and efficient. Similarly, if I were using a recursive LISP style approach, positions, or index values, do not matter either: function Count (A : String; X : Character) return Integer is function Count_Loop (K : Positive) return Natural is begin if K <= A'Last then return "+" (Boolean'Pos ("=" (A(K), X)), Count_Loop (Positive'Succ (K))); else return 0; end if; end Count_Loop; begin return Count_Loop (A'First); end Count;